use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.
the class JavaIntroduceVariableTest method doTest.
protected static void doTest(String expression, VariableKind kind, PsiType type, String... results) throws Exception {
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(getProject());
final PsiExpression expr = factory.createExpressionFromText(expression, null);
final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(getProject());
final SuggestedNameInfo info = codeStyleManager.suggestVariableName(kind, null, expr, type);
assert info.names.length >= results.length : msg("Can't find some variants", info.names, results);
for (int i = 0; i < results.length; i++) {
if (!results[i].equals(info.names[i])) {
throw new Exception(msg("", info.names, results));
}
}
}
use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.
the class InplaceIntroduceVariableTest 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);
if (expr == null && InjectedLanguageManager.getInstance(getProject()).isInjectedFragment(getFile())) {
return PsiTreeUtil.getParentOfType(InjectedLanguageUtil.getTopLevelFile(getFile()).findElementAt(InjectedLanguageUtil.getTopLevelEditor(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 ValueDescriptorImpl method getTreeEvaluation.
//returns expression that evaluates tree to this descriptor
@Nullable
public PsiElement getTreeEvaluation(JavaValue value, DebuggerContextImpl context) throws EvaluateException {
JavaValue parent = value.getParent();
if (parent != null) {
ValueDescriptorImpl vDescriptor = parent.getDescriptor();
PsiElement parentEvaluation = vDescriptor.getTreeEvaluation(parent, context);
if (!(parentEvaluation instanceof PsiExpression)) {
return null;
}
return DebuggerTreeNodeExpression.substituteThis(vDescriptor.getRenderer(context.getDebugProcess()).getChildValueExpression(new DebuggerTreeNodeMock(value), context), ((PsiExpression) parentEvaluation), vDescriptor.getValue());
}
return getDescriptorEvaluation(context);
}
use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.
the class JavaExpressionSurroundDescriptor method getElementsToSurround.
@Override
@NotNull
public PsiElement[] getElementsToSurround(PsiFile file, int startOffset, int endOffset) {
PsiExpression expr = CodeInsightUtil.findExpressionInRange(file, startOffset, endOffset);
if (expr == null) {
expr = IntroduceVariableBase.getSelectedExpression(file.getProject(), file, startOffset, endOffset);
if (expr == null) {
return PsiElement.EMPTY_ARRAY;
}
}
FeatureUsageTracker.getInstance().triggerFeatureUsed("codeassists.surroundwith.expression");
return new PsiElement[] { expr };
}
use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.
the class ConcatenationToMessageFormatActionTest method doTest.
public void doTest(String expressionText, String messageFormatText, String... foundExpressionTexts) {
final PsiExpression expression = JavaPsiFacade.getElementFactory(getProject()).createExpressionFromText(expressionText, null);
final StringBuilder result = new StringBuilder();
final ArrayList<PsiExpression> args = new ArrayList<>();
PsiConcatenationUtil.buildFormatString(expression, result, args, false);
assertEquals(messageFormatText, result.toString());
assertEquals(foundExpressionTexts.length, args.size());
for (int i = 0; i < foundExpressionTexts.length; i++) {
final String foundExpressionText = foundExpressionTexts[i];
assertEquals(foundExpressionText, args.get(i).getText());
}
}
Aggregations