Search in sources :

Example 61 with PsiExpression

use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.

the class GuessExprTypeTest method guessExprTypes.

private static PsiType[] guessExprTypes() {
    int offset1 = getEditor().getSelectionModel().getSelectionStart();
    int offset2 = getEditor().getSelectionModel().getSelectionEnd();
    PsiExpression expr = CodeInsightUtil.findExpressionInRange(getFile(), offset1, offset2);
    assertNotNull(expr);
    return GuessManager.getInstance(getProject()).guessTypeToCast(expr);
}
Also used : PsiExpression(com.intellij.psi.PsiExpression)

Example 62 with PsiExpression

use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.

the class ReplaceThisCallWithDelegateCall method fixUsage.

public void fixUsage() throws IncorrectOperationException {
    final PsiReferenceExpression methodExpression = call.getMethodExpression();
    final PsiExpression qualifierExpression = methodExpression.getQualifierExpression();
    if (qualifierExpression == null) {
        MutationUtils.replaceExpression(delegateFieldName + '.' + call.getText(), call);
    } else {
        MutationUtils.replaceExpression(delegateFieldName, qualifierExpression);
    }
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiReferenceExpression(com.intellij.psi.PsiReferenceExpression)

Example 63 with PsiExpression

use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.

the class InplaceIntroduceConstantTest method getExpressionFromEditor.

@Nullable
@Override
protected PsiExpression getExpressionFromEditor() {
    final PsiExpression expression = super.getExpressionFromEditor();
    if (expression != null) {
        return expression;
    }
    final PsiExpression expr = PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), PsiExpression.class);
    return expr instanceof PsiLiteralExpression ? expr : null;
}
Also used : PsiLiteralExpression(com.intellij.psi.PsiLiteralExpression) PsiExpression(com.intellij.psi.PsiExpression) Nullable(org.jetbrains.annotations.Nullable)

Example 64 with PsiExpression

use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.

the class ExtractMethodObjectWithMultipleExitPointsTest method doTest.

private void doTest(final boolean createInnerClass) throws Exception {
    final String testName = getTestName(false);
    configureByFile("/refactoring/extractMethodObject/multipleExitPoints/" + testName + ".java");
    int startOffset = myEditor.getSelectionModel().getSelectionStart();
    int endOffset = myEditor.getSelectionModel().getSelectionEnd();
    final PsiElement[] elements;
    PsiExpression expr = CodeInsightUtil.findExpressionInRange(myFile, startOffset, endOffset);
    if (expr != null) {
        elements = new PsiElement[] { expr };
    } else {
        elements = CodeInsightUtil.findStatementsInRange(myFile, startOffset, endOffset);
    }
    final ExtractMethodObjectProcessor processor = new ExtractMethodObjectProcessor(getProject(), getEditor(), elements, "Inner");
    final ExtractMethodObjectProcessor.MyExtractMethodProcessor extractProcessor = processor.getExtractProcessor();
    extractProcessor.setShowErrorDialogs(false);
    extractProcessor.prepare();
    extractProcessor.testPrepare();
    processor.setCreateInnerClass(createInnerClass);
    ExtractMethodObjectHandler.run(getProject(), getEditor(), processor, extractProcessor);
    checkResultByFile("/refactoring/extractMethodObject/multipleExitPoints/" + testName + ".java" + ".after");
}
Also used : ExtractMethodObjectProcessor(com.intellij.refactoring.extractMethodObject.ExtractMethodObjectProcessor) PsiExpression(com.intellij.psi.PsiExpression) PsiElement(com.intellij.psi.PsiElement)

Example 65 with PsiExpression

use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.

the class SuggestedReturnTypesTest method doTest.

private void doTest(String... types) throws Exception {
    configureByFile(BASE_PATH + getTestName(false) + ".java");
    final Editor editor = getEditor();
    final PsiFile file = getFile();
    final Project project = getProject();
    int startOffset = editor.getSelectionModel().getSelectionStart();
    int endOffset = editor.getSelectionModel().getSelectionEnd();
    PsiElement[] elements;
    PsiExpression expr = CodeInsightUtil.findExpressionInRange(file, startOffset, endOffset);
    if (expr != null) {
        elements = new PsiElement[] { expr };
    } else {
        elements = CodeInsightUtil.findStatementsInRange(file, startOffset, endOffset);
    }
    assertTrue(elements.length > 0);
    final ExtractMethodProcessor processor = new ExtractMethodProcessor(project, editor, elements, null, "Extract Method", "newMethod", null);
    processor.prepare();
    final PsiExpression[] occurrences = processor.findOccurrences();
    final TypeSelectorManager manager = new TypeSelectorManagerImpl(project, processor.getReturnType(), occurrences, true);
    final JComponent component = manager.getTypeSelector().getComponent();
    if (types.length > 1) {
        assertTrue("One type suggested", component instanceof JComboBox);
        final DefaultComboBoxModel model = (DefaultComboBoxModel) ((JComboBox) component).getModel();
        assertEquals(types.length, model.getSize());
        for (int i = 0, typesLength = types.length; i < typesLength; i++) {
            String type = types[i];
            assertEquals(type, model.getElementAt(i).toString());
        }
    } else if (types.length == 1) {
        assertTrue("Multiple types suggested", component instanceof JLabel);
        assertEquals(types[0], ((JLabel) component).getText());
    }
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) ExtractMethodProcessor(com.intellij.refactoring.extractMethod.ExtractMethodProcessor) Project(com.intellij.openapi.project.Project) TypeSelectorManager(com.intellij.refactoring.ui.TypeSelectorManager) TypeSelectorManagerImpl(com.intellij.refactoring.ui.TypeSelectorManagerImpl) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiExpression (com.intellij.psi.PsiExpression)67 PsiElement (com.intellij.psi.PsiElement)24 PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)11 PsiMethodCallExpression (com.intellij.psi.PsiMethodCallExpression)8 NonNls (org.jetbrains.annotations.NonNls)8 PsiLocalVariable (com.intellij.psi.PsiLocalVariable)7 PsiType (com.intellij.psi.PsiType)7 PsiAssignmentExpression (com.intellij.psi.PsiAssignmentExpression)6 PsiExpressionStatement (com.intellij.psi.PsiExpressionStatement)6 PsiPolyadicExpression (com.intellij.psi.PsiPolyadicExpression)6 PsiStatement (com.intellij.psi.PsiStatement)6 Nullable (org.jetbrains.annotations.Nullable)6 PsiBinaryExpression (com.intellij.psi.PsiBinaryExpression)5 PsiClass (com.intellij.psi.PsiClass)5 PsiDeclarationStatement (com.intellij.psi.PsiDeclarationStatement)5 PsiElementFactory (com.intellij.psi.PsiElementFactory)5 PsiField (com.intellij.psi.PsiField)5 PsiReference (com.intellij.psi.PsiReference)5 Nullable (com.android.annotations.Nullable)4 Project (com.intellij.openapi.project.Project)4