use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.
the class SuggestedParamTypesTest 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();
for (final VariableData data : processor.getInputVariables().getInputVariables()) {
final PsiExpression[] occurrences = ParameterTablePanel.findVariableOccurrences(elements, data.variable);
final TypeSelectorManager manager = new TypeSelectorManagerImpl(project, data.type, occurrences, true) {
@Override
protected boolean isUsedAfter() {
return processor.isOutputVariable(data.variable);
}
};
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());
}
}
}
use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.
the class InstructionVisitor method visitMethodCall.
public DfaInstructionState[] visitMethodCall(MethodCallInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) {
//noinspection UnusedDeclaration
for (PsiExpression arg : instruction.getArgs()) {
memState.pop();
}
//qualifier
memState.pop();
memState.push(DfaUnknownValue.getInstance());
return nextInstruction(instruction, runner, memState);
}
use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.
the class SmartCompletionTemplateItem method getType.
@Override
public PsiType getType() {
final Template template = getTemplate();
String text = template.getTemplateText();
StringBuilder resultingText = new StringBuilder(text);
int segmentsCount = template.getSegmentsCount();
for (int j = segmentsCount - 1; j >= 0; j--) {
if (template.getSegmentName(j).equals(TemplateImpl.END)) {
continue;
}
resultingText.insert(template.getSegmentOffset(j), "xxx");
}
try {
final PsiExpression templateExpression = JavaPsiFacade.getElementFactory(myContext.getProject()).createExpressionFromText(resultingText.toString(), myContext);
return templateExpression.getType();
} catch (IncorrectOperationException e) {
// can happen when text of the template does not form an expression
return null;
}
}
use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.
the class WrapReturnValue method fixUsage.
@Override
public void fixUsage() throws IncorrectOperationException {
PsiExpression returnValue = myStatement.getReturnValue();
assert returnValue != null;
String newExpression = "new " + myType + '(' + returnValue.getText() + ')';
MutationUtils.replaceExpression(newExpression, returnValue);
}
use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.
the class JavaPsiFormattingTest method testReferenceExpressionSpaceInsertion.
public void testReferenceExpressionSpaceInsertion() {
String text = "if(x&y);";
PsiFile file = createFile("A.java", "class C{{\n" + text + "\n}}");
PsiElement element = file.findElementAt(file.getText().indexOf(text));
PsiIfStatement statement = PsiTreeUtil.getParentOfType(element, PsiIfStatement.class);
assertNotNull(statement);
Ref<PsiElement> result = Ref.create();
CommandProcessor.getInstance().executeCommand(getProject(), () -> WriteAction.run(() -> result.set(CodeStyleManager.getInstance(getProject()).reformat(statement))), "", null);
PsiExpression expr = ((PsiIfStatement) result.get()).getCondition();
assertEquals("PsiBinaryExpression:x & y\n" + " PsiReferenceExpression:x\n" + " PsiReferenceParameterList\n" + " <empty list>\n" + " PsiIdentifier:x('x')\n" + " PsiWhiteSpace(' ')\n" + " PsiJavaToken:AND('&')\n" + " PsiWhiteSpace(' ')\n" + " PsiReferenceExpression:y\n" + " PsiReferenceParameterList\n" + " <empty list>\n" + " PsiIdentifier:y('y')\n", DebugUtil.psiToString(expr, false));
}
Aggregations