diff --git a/java/debugger/impl/src/com/intellij/debugger/memory/filtering/ConditionCheckerImpl.java b/java/debugger/impl/src/com/intellij/debugger/memory/filtering/ConditionCheckerImpl.java index 45752525aa29..30b89c86a3cf 100644 --- a/java/debugger/impl/src/com/intellij/debugger/memory/filtering/ConditionCheckerImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/memory/filtering/ConditionCheckerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,12 +22,11 @@ import com.intellij.debugger.engine.evaluation.EvaluationContextImpl; import com.intellij.debugger.engine.evaluation.TextWithImportsImpl; import com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator; import com.intellij.debugger.engine.events.DebuggerContextCommandImpl; +import com.intellij.debugger.impl.DebuggerUtilsEx; import com.intellij.debugger.ui.tree.render.CachedEvaluator; import com.intellij.openapi.project.Project; import com.intellij.xdebugger.XExpression; -import com.sun.jdi.BooleanValue; import com.sun.jdi.ObjectReference; -import com.sun.jdi.Value; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -70,17 +69,11 @@ public class ConditionCheckerImpl implements ConditionChecker { @Override public void threadAction(@NotNull SuspendContextImpl suspendContext) { - ExpressionEvaluator evaluator; try { - evaluator = myEvaluator.getEvaluator(); - Value result = - evaluator.evaluate(new EvaluationContextImpl(suspendContext, suspendContext.getFrameProxy(), myReference)); - if (result instanceof BooleanValue && ((BooleanValue)result).value()) { - myResultReference.set(CheckingResultImpl.SUCCESS); - } - else { - myResultReference.set(CheckingResultImpl.FAIL); - } + EvaluationContextImpl evaluationContext = new EvaluationContextImpl(suspendContext, suspendContext.getFrameProxy(), myReference); + myResultReference.set(DebuggerUtilsEx.evaluateBoolean(myEvaluator.getEvaluator(), evaluationContext) + ? CheckingResultImpl.SUCCESS + : CheckingResultImpl.FAIL); } catch (EvaluateException e) { myResultReference.set(CheckingResultImpl.error(e.getMessage())); diff --git a/uast/uast-java/src/org/jetbrains/uast/java/JavaUastLanguagePlugin.kt b/uast/uast-java/src/org/jetbrains/uast/java/JavaUastLanguagePlugin.kt index afe5b8660f03..89a87fb8d539 100644 --- a/uast/uast-java/src/org/jetbrains/uast/java/JavaUastLanguagePlugin.kt +++ b/uast/uast-java/src/org/jetbrains/uast/java/JavaUastLanguagePlugin.kt @@ -159,6 +159,7 @@ internal object JavaConverter { is PsiParameterList -> unwrapElements(element.parent) is PsiAnnotationParameterList -> unwrapElements(element.parent) is PsiModifierList -> unwrapElements(element.parent) + is PsiExpressionList -> unwrapElements(element.parent) else -> element } @@ -228,14 +229,23 @@ internal object JavaConverter { expr(build(::JavaConstructorUCallExpression)) } is PsiMethodCallExpression -> { - if (el.methodExpression.qualifierExpression != null) - expr { + if (el.methodExpression.qualifierExpression != null) { + if (requiredType == null || + requiredType.isAssignableFrom(UQualifiedReferenceExpression::class.java) || + requiredType.isAssignableFrom(UCallExpression::class.java)) { val parent = if (parentCallback == null) null else (parentCallback() ?: return null) - JavaUCompositeQualifiedExpression(el, parent).apply { + val expr = JavaUCompositeQualifiedExpression(el, parent).apply { receiver = convertOrEmpty(el.methodExpression.qualifierExpression!!, this) selector = JavaUCallExpression(el, this) } + if (requiredType?.isAssignableFrom(UCallExpression::class.java) != null) + expr.selector + else + expr } + else + null + } else expr(build(::JavaUCallExpression)) } diff --git a/uast/uast-tests/java/Simple/CallExpression.java b/uast/uast-tests/java/Simple/CallExpression.java new file mode 100644 index 000000000000..b9993d9eb509 --- /dev/null +++ b/uast/uast-tests/java/Simple/CallExpression.java @@ -0,0 +1,18 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +public class Foo { + public static String foo = String.format("q"); +} diff --git a/uast/uast-tests/test/org/jetbrains/uast/test/java/JavaUastApiTest.kt b/uast/uast-tests/test/org/jetbrains/uast/test/java/JavaUastApiTest.kt index 0a04fff01dd0..19cb16aea445 100644 --- a/uast/uast-tests/test/org/jetbrains/uast/test/java/JavaUastApiTest.kt +++ b/uast/uast-tests/test/org/jetbrains/uast/test/java/JavaUastApiTest.kt @@ -15,8 +15,11 @@ */ package org.jetbrains.uast.test.java -import org.jetbrains.uast.UFile -import org.jetbrains.uast.ULocalVariable +import com.intellij.psi.PsiCallExpression +import com.intellij.psi.PsiLiteralExpression +import com.intellij.psi.util.PsiTreeUtil +import com.intellij.testFramework.UsefulTestCase +import org.jetbrains.uast.* import org.jetbrains.uast.test.env.findElementByText import org.junit.Test @@ -37,4 +40,16 @@ class JavaUastApiTest : AbstractJavaUastTest() { assertEquals(1, file.classes[0].fields.size) } } + + @Test fun testCallExpression() { + doTest("Simple/CallExpression.java") { name, file -> + val index = file.psi.text.indexOf("format") + val callExpression = PsiTreeUtil.getParentOfType(file.psi.findElementAt(index), PsiCallExpression::class.java)!! + assertNotNull(callExpression.toUElementOfType()) + + val index2 = file.psi.text.indexOf("q") + val literal = PsiTreeUtil.getParentOfType(file.psi.findElementAt(index2), PsiLiteralExpression::class.java)!! + UsefulTestCase.assertInstanceOf(literal.toUElement(), ULiteralExpression::class.java) + } + } }