Search in sources :

Example 21 with PsiExpression

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));
        }
    }
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) JavaCodeStyleManager(com.intellij.psi.codeStyle.JavaCodeStyleManager) PsiElementFactory(com.intellij.psi.PsiElementFactory) SuggestedNameInfo(com.intellij.psi.codeStyle.SuggestedNameInfo)

Example 22 with PsiExpression

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;
}
Also used : PsiLiteralExpression(com.intellij.psi.PsiLiteralExpression) PsiExpression(com.intellij.psi.PsiExpression) Nullable(org.jetbrains.annotations.Nullable)

Example 23 with PsiExpression

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);
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 24 with PsiExpression

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 };
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with PsiExpression

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());
    }
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) ArrayList(java.util.ArrayList)

Aggregations

PsiExpression (com.intellij.psi.PsiExpression)72 PsiElement (com.intellij.psi.PsiElement)28 PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)13 PsiMethodCallExpression (com.intellij.psi.PsiMethodCallExpression)11 Nullable (org.jetbrains.annotations.Nullable)9 PsiReference (com.intellij.psi.PsiReference)8 PsiType (com.intellij.psi.PsiType)8 NonNls (org.jetbrains.annotations.NonNls)8 PsiClass (com.intellij.psi.PsiClass)7 PsiAssignmentExpression (com.intellij.psi.PsiAssignmentExpression)6 PsiExpressionStatement (com.intellij.psi.PsiExpressionStatement)6 PsiLocalVariable (com.intellij.psi.PsiLocalVariable)6 PsiMethod (com.intellij.psi.PsiMethod)6 PsiNewExpression (com.intellij.psi.PsiNewExpression)6 PsiPolyadicExpression (com.intellij.psi.PsiPolyadicExpression)6 PsiStatement (com.intellij.psi.PsiStatement)6 Project (com.intellij.openapi.project.Project)5 PsiBinaryExpression (com.intellij.psi.PsiBinaryExpression)5 PsiDeclarationStatement (com.intellij.psi.PsiDeclarationStatement)5 PsiElementFactory (com.intellij.psi.PsiElementFactory)5