Search in sources :

Example 21 with Editor

use of com.intellij.openapi.editor.Editor in project intellij-community by JetBrains.

the class PyUnwrapperTest method doTest.

private void doTest(final int option) {
    String before = "refactoring/unwrap/" + getTestName(true) + "_before.py";
    String after = "refactoring/unwrap/" + getTestName(true) + "_after.py";
    myFixture.configureByFile(before);
    UnwrapHandler h = new UnwrapHandler() {

        @Override
        protected void selectOption(List<AnAction> options, Editor editor, PsiFile file) {
            assertTrue("No available options to unwrap", !options.isEmpty());
            options.get(option).actionPerformed(null);
        }
    };
    h.invoke(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile());
    myFixture.checkResultByFile(after, true);
}
Also used : UnwrapHandler(com.intellij.codeInsight.unwrap.UnwrapHandler) List(java.util.List) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor)

Example 22 with Editor

use of com.intellij.openapi.editor.Editor in project intellij-community by JetBrains.

the class PyUnwrapperTest method doNegativeTest.

private void doNegativeTest(final String optionName) {
    String before = "refactoring/unwrap/" + getTestName(true) + "_before.py";
    myFixture.configureByFile(before);
    UnwrapHandler h = new UnwrapHandler() {

        @Override
        protected void selectOption(List<AnAction> options, Editor editor, PsiFile file) {
            for (AnAction option : options) {
                assertFalse("\"" + optionName + "\" is available to unwrap ", option.toString().contains(optionName));
            }
        }
    };
    h.invoke(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile());
}
Also used : UnwrapHandler(com.intellij.codeInsight.unwrap.UnwrapHandler) List(java.util.List) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 23 with Editor

use of com.intellij.openapi.editor.Editor in project intellij-community by JetBrains.

the class GroovyTestGenerator method generateTest.

@Nullable
@Override
public PsiElement generateTest(final Project project, final CreateTestDialog d) {
    return WriteAction.compute(() -> {
        final PsiClass test = (PsiClass) PostprocessReformattingAspect.getInstance(project).postponeFormattingInside((Computable<PsiElement>) () -> {
            try {
                IdeDocumentHistory.getInstance(project).includeCurrentPlaceAsChangePlace();
                GrTypeDefinition targetClass = CreateClassActionBase.createClassByType(d.getTargetDirectory(), d.getClassName(), PsiManager.getInstance(project), null, GroovyTemplates.GROOVY_CLASS, true);
                if (targetClass == null)
                    return null;
                addSuperClass(targetClass, project, d.getSuperClassName());
                Editor editor = CodeInsightUtil.positionCursorAtLBrace(project, targetClass.getContainingFile(), targetClass);
                addTestMethods(editor, targetClass, d.getSelectedTestFrameworkDescriptor(), d.getSelectedMethods(), d.shouldGeneratedBefore(), d.shouldGeneratedAfter());
                return targetClass;
            } catch (IncorrectOperationException e1) {
                showErrorLater(project, d.getClassName());
                return null;
            }
        });
        if (test == null)
            return null;
        JavaCodeStyleManager.getInstance(test.getProject()).shortenClassReferences(test);
        CodeStyleManager.getInstance(project).reformat(test);
        return test;
    });
}
Also used : GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Editor(com.intellij.openapi.editor.Editor) Computable(com.intellij.openapi.util.Computable) Nullable(org.jetbrains.annotations.Nullable)

Example 24 with Editor

use of com.intellij.openapi.editor.Editor in project intellij-community by JetBrains.

the class IntroduceVariableValidatorTest method processFile.

private String processFile(String fileText) throws IncorrectOperationException, InvalidDataException, IOException {
    String result = "";
    int startOffset = fileText.indexOf(TestUtils.BEGIN_MARKER);
    if (startOffset < 0) {
        startOffset = fileText.indexOf(ALL_MARKER);
        replaceAllOccurences = true;
        fileText = IntroduceVariableTest.removeAllMarker(fileText);
    } else {
        replaceAllOccurences = false;
        fileText = TestUtils.removeBeginMarker(fileText);
    }
    int endOffset = fileText.indexOf(TestUtils.END_MARKER);
    fileText = TestUtils.removeEndMarker(fileText);
    myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, fileText);
    Editor myEditor = myFixture.getEditor();
    myEditor.getSelectionModel().setSelection(startOffset, endOffset);
    GrExpression selectedExpr = PsiImplUtil.findElementInRange(myFixture.getFile(), startOffset, endOffset, GrExpression.class);
    Assert.assertNotNull("Selected expression reference points to null", selectedExpr);
    final PsiElement tempContainer = GrIntroduceHandlerBase.getEnclosingContainer(selectedExpr);
    Assert.assertTrue(tempContainer instanceof GroovyPsiElement);
    PsiElement[] occurences = GroovyRefactoringUtil.getExpressionOccurrences(PsiUtil.skipParentheses(selectedExpr, false), tempContainer);
    String varName = "preved";
    GroovyVariableValidator validator = new GroovyVariableValidator(new GrIntroduceContextImpl(getProject(), myEditor, selectedExpr, null, null, occurences, tempContainer));
    result = validator.isOKTest(varName, replaceAllOccurences);
    return result;
}
Also used : GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) Editor(com.intellij.openapi.editor.Editor) GroovyVariableValidator(org.jetbrains.plugins.groovy.refactoring.introduce.variable.GroovyVariableValidator) GrIntroduceContextImpl(org.jetbrains.plugins.groovy.refactoring.introduce.GrIntroduceContextImpl) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 25 with Editor

use of com.intellij.openapi.editor.Editor in project intellij-community by JetBrains.

the class XPathAction method isEnabled.

protected boolean isEnabled(AnActionEvent event, boolean checkAvailable) {
    final Project project = event.getProject();
    if (project == null) {
        // no active project
        return false;
    }
    Editor editor = CommonDataKeys.EDITOR.getData(event.getDataContext());
    if (editor == null) {
        FileEditorManager fem = FileEditorManager.getInstance(project);
        editor = fem.getSelectedTextEditor();
    }
    if (editor == null) {
        return false;
    }
    // do we have an xml file?
    final PsiDocumentManager cem = PsiDocumentManager.getInstance(project);
    final PsiFile psiFile = cem.getPsiFile(editor.getDocument());
    // this is also true for DTD documents...
    if (!(psiFile instanceof XmlFile) || psiFile.getLanguage() == StdFileTypes.DTD.getLanguage()) {
        return false;
    }
    return !checkAvailable || isEnabledAt((XmlFile) psiFile, editor.getCaretModel().getOffset());
}
Also used : Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) XmlFile(com.intellij.psi.xml.XmlFile) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Aggregations

Editor (com.intellij.openapi.editor.Editor)745 Project (com.intellij.openapi.project.Project)280 PsiFile (com.intellij.psi.PsiFile)169 VirtualFile (com.intellij.openapi.vfs.VirtualFile)121 NotNull (org.jetbrains.annotations.NotNull)110 Document (com.intellij.openapi.editor.Document)108 PsiElement (com.intellij.psi.PsiElement)106 Nullable (org.jetbrains.annotations.Nullable)103 TextRange (com.intellij.openapi.util.TextRange)76 FileEditor (com.intellij.openapi.fileEditor.FileEditor)67 TextEditor (com.intellij.openapi.fileEditor.TextEditor)48 ArrayList (java.util.ArrayList)39 IncorrectOperationException (com.intellij.util.IncorrectOperationException)36 List (java.util.List)36 EditorEx (com.intellij.openapi.editor.ex.EditorEx)35 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)28 DataContext (com.intellij.openapi.actionSystem.DataContext)26 ApplicationManager (com.intellij.openapi.application.ApplicationManager)25 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)25 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)22