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);
}
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);
}
}
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;
}
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");
}
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());
}
}
Aggregations