mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
+3
-1
@@ -315,7 +315,9 @@ public class CreatePropertyFromUsageFix extends CreateFromUsageBaseFix implement
|
||||
}
|
||||
|
||||
protected void beforeTemplateFinished(PsiClass aClass, PsiField field) {
|
||||
positionCursor(myMethodCall.getProject(), myMethodCall.getContainingFile(), myMethodCall);
|
||||
if (myMethodCall.isValid()) {
|
||||
positionCursor(myMethodCall.getProject(), myMethodCall.getContainingFile(), myMethodCall);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getVariableName(PsiMethodCallExpression methodCall, boolean isStatic) {
|
||||
|
||||
+1
@@ -48,6 +48,7 @@ public class AddOverrideAnnotationAction implements IntentionAction {
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
if (!PsiUtil.isLanguageLevel5OrHigher(file)) return false;
|
||||
if (!file.getManager().isInProject(file)) return false;
|
||||
PsiMethod method = findMethod(file, editor.getCaretModel().getOffset());
|
||||
if (method == null) return false;
|
||||
if (method.getModifierList().findAnnotation(JAVA_LANG_OVERRIDE) != null) return false;
|
||||
|
||||
@@ -126,22 +126,29 @@ public class LambdaUtil {
|
||||
}
|
||||
LOG.assertTrue(psiClass != null);
|
||||
PsiType methodReturnType = getReturnType(psiClass, methodSignature);
|
||||
if (methodReturnType != null && methodReturnType != PsiType.VOID) {
|
||||
methodReturnType = resolveResult.getSubstitutor().substitute(methodSignature.getSubstitutor().substitute(methodReturnType));
|
||||
final PsiElement body = lambdaExpression.getBody();
|
||||
if (body instanceof PsiCodeBlock) {
|
||||
final PsiCodeBlock block = (PsiCodeBlock)body;
|
||||
for (PsiStatement statement : block.getStatements()) {
|
||||
if (statement instanceof PsiReturnStatement) {
|
||||
final PsiExpression returnValue = ((PsiReturnStatement)statement).getReturnValue();
|
||||
if (returnValue != null) {
|
||||
if (!checkReturnTypeAssignability(returnValue.getType(), parameterTypes, lambdaExpression, methodReturnType)) return false;
|
||||
if (methodReturnType != null) {
|
||||
if (methodReturnType != PsiType.VOID) {
|
||||
methodReturnType = resolveResult.getSubstitutor().substitute(methodSignature.getSubstitutor().substitute(methodReturnType));
|
||||
final PsiElement body = lambdaExpression.getBody();
|
||||
if (body instanceof PsiCodeBlock) {
|
||||
final PsiCodeBlock block = (PsiCodeBlock)body;
|
||||
for (PsiStatement statement : block.getStatements()) {
|
||||
if (statement instanceof PsiReturnStatement) {
|
||||
final PsiExpression returnValue = ((PsiReturnStatement)statement).getReturnValue();
|
||||
if (returnValue != null) {
|
||||
if (!checkReturnTypeAssignability(returnValue.getType(), parameterTypes, lambdaExpression, methodReturnType)) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (body instanceof PsiExpression) {
|
||||
return checkReturnTypeAssignability(((PsiExpression)body).getType(), parameterTypes, lambdaExpression, methodReturnType);
|
||||
else if (body instanceof PsiExpression) {
|
||||
return checkReturnTypeAssignability(((PsiExpression)body).getType(), parameterTypes, lambdaExpression, methodReturnType);
|
||||
}
|
||||
} else {
|
||||
final List<PsiExpression> returnExpressions = lambdaExpression.getReturnExpressions();
|
||||
for (PsiExpression returnValue : returnExpressions) {
|
||||
if (returnValue.getType() != PsiType.VOID) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
+21
-5
@@ -19,6 +19,7 @@ import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.tree.java.PsiLambdaExpressionImpl;
|
||||
import com.intellij.psi.infos.CandidateInfo;
|
||||
import com.intellij.psi.infos.MethodCandidateInfo;
|
||||
import com.intellij.psi.scope.MethodProcessorSetupFailedException;
|
||||
@@ -595,6 +596,7 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
|
||||
final PsiSubstitutor subst = resolveResult.getSubstitutor();
|
||||
final PsiType returnType = subst.substitute(method.getReturnType());
|
||||
if (returnType != null && returnType != PsiType.VOID) {
|
||||
Pair<PsiType, ConstraintType> constraint = null;
|
||||
final List<PsiExpression> expressions = lambdaExpression.getReturnExpressions();
|
||||
for (final PsiExpression expression : expressions) {
|
||||
final boolean independent = LambdaUtil.isFreeFromTypeInferenceArgs(methodParameters, lambdaExpression, expression);
|
||||
@@ -621,12 +623,20 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
|
||||
if (exprType == null){
|
||||
return FAILED_INFERENCE;
|
||||
}
|
||||
Pair<PsiType, ConstraintType> constraint =
|
||||
|
||||
final Pair<PsiType, ConstraintType> returnExprConstraint =
|
||||
getSubstitutionForTypeParameterConstraint(typeParam, returnType, exprType, false, PsiUtil.getLanguageLevel(method));
|
||||
if (constraint != null) {
|
||||
return constraint; //todo check that all return statements lead to the same inference
|
||||
if (returnExprConstraint != null) {
|
||||
if (returnExprConstraint == FAILED_INFERENCE) return returnExprConstraint;
|
||||
if (constraint != null) {
|
||||
final PsiType leastUpperBound = GenericsUtil.getLeastUpperBound(constraint.getFirst(), returnExprConstraint.getFirst(), typeParam.getManager());
|
||||
constraint = new Pair<PsiType, ConstraintType>(leastUpperBound, ConstraintType.SUPERTYPE);
|
||||
} else {
|
||||
constraint = returnExprConstraint;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (constraint != null) return constraint;
|
||||
}
|
||||
for (PsiParameter parameter : methodParameters) {
|
||||
if (LambdaUtil.dependsOnTypeParams(parameter.getType(), lambdaExpression)) {
|
||||
@@ -867,8 +877,14 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
|
||||
final PsiExpressionList argumentList = methodCall.getArgumentList();
|
||||
if (argumentList != null && PsiUtil.getLanguageLevel(argumentList).isAtLeast(LanguageLevel.JDK_1_8)) {
|
||||
for (PsiExpression expression : argumentList.getExpressions()) {
|
||||
if (expression instanceof PsiLambdaExpression){
|
||||
return getFailedInferenceConstraint(typeParameter);
|
||||
if (expression instanceof PsiLambdaExpression) {
|
||||
if (((PsiLambdaExpression)expression).getParameterList().getParametersCount() > 0){
|
||||
return getFailedInferenceConstraint(typeParameter);
|
||||
}
|
||||
final PsiType functionalInterfaceType = PsiLambdaExpressionImpl.getFunctionalInterfaceType(((PsiLambdaExpression)expression), false);
|
||||
if (functionalInterfaceType == null || PsiUtil.resolveClassInType(functionalInterfaceType) == typeParameter){
|
||||
return getFailedInferenceConstraint(typeParameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ class ReturnTypeCompatibility {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
call(<error descr="Cyclic inference">i-> {return i;}</error>);
|
||||
<error descr="Cannot resolve method 'call(<lambda expression>)'">call</error>(i-> {return i;});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+25
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.
|
||||
*/
|
||||
import java.util.List;
|
||||
class Test1 {
|
||||
|
||||
@@ -23,6 +38,16 @@ class Test1 {
|
||||
bar2("", x -> x);
|
||||
|
||||
bar3(x -> x, "");
|
||||
|
||||
int ixc = 42;
|
||||
bar(x -> {
|
||||
if (ixc == 2) return "aaa";
|
||||
return x;
|
||||
});
|
||||
bar(x -> {
|
||||
if (ixc == 2) return x;
|
||||
return x;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
import java.util.*;
|
||||
class Test4 {
|
||||
interface I<K> {
|
||||
List<K> foo();
|
||||
}
|
||||
|
||||
static <T> void bar(I<T> i){}
|
||||
|
||||
{
|
||||
bar(() -> null);
|
||||
}
|
||||
}
|
||||
|
||||
class Test5 {
|
||||
interface I<K> {
|
||||
void foo(K k);
|
||||
}
|
||||
|
||||
static <T> void bar(I<T> i){}
|
||||
|
||||
{
|
||||
bar<error descr="'bar(Test5.I<T>)' in 'Test5' cannot be applied to '(<lambda expression>)'">(() -> null)</error>;
|
||||
}
|
||||
}
|
||||
class Test6 {
|
||||
interface I<K> {
|
||||
void foo();
|
||||
}
|
||||
|
||||
static <T> void bar(I<T> i){}
|
||||
|
||||
{
|
||||
bar<error descr="'bar(Test6.I<java.lang.Object>)' in 'Test6' cannot be applied to '(<lambda expression>)'">(() -> null)</error>;
|
||||
bar(() -> {});
|
||||
}
|
||||
}
|
||||
+4
@@ -49,6 +49,10 @@ public class LambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testTypeArgsConsistencyWithoutParams() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testWildcardBounds() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@@ -129,7 +129,13 @@ public abstract class RemoteProcessSupport<Target, EntryPoint, Parameters> {
|
||||
}
|
||||
if (ref.isNull()) throw new RuntimeException("Unable to acquire remote proxy for: " + getName(target));
|
||||
RunningInfo info = ref.get();
|
||||
if (info.handler == null) throw new ExecutionException(info.name);
|
||||
if (info.handler == null) {
|
||||
String message = info.name;
|
||||
if (message != null && message.startsWith("ERROR: transport error 202:")) {
|
||||
message = "Unable to start java process in debug mode: -Xdebug parameters are already in use.";
|
||||
}
|
||||
throw new ExecutionException(message);
|
||||
}
|
||||
return acquire(info);
|
||||
}
|
||||
|
||||
|
||||
@@ -268,8 +268,9 @@ public class DebuggerUIUtil {
|
||||
editor.setPropertiesPanel(mainPanel);
|
||||
editor.setShowMoreOptionsLink(true);
|
||||
|
||||
final JPanel panel = editor.getMainPanel();
|
||||
final Balloon balloon = JBPopupFactory.getInstance()
|
||||
.createDialogBalloonBuilder(editor.getMainPanel(), null)
|
||||
.createDialogBalloonBuilder(panel, null)
|
||||
.setHideOnClickOutside(true)
|
||||
.setCloseButtonEnabled(false)
|
||||
.setAnimationCycle(0)
|
||||
@@ -295,7 +296,16 @@ public class DebuggerUIUtil {
|
||||
balloon.showInCenterOf(component);
|
||||
}
|
||||
else {
|
||||
balloon.show(new RelativePoint(component, whereToShow), Balloon.Position.below);
|
||||
//todo[kb] modify and move to BalloonImpl?
|
||||
final Window window = SwingUtilities.windowForComponent(component);
|
||||
final RelativePoint p = new RelativePoint(component, whereToShow);
|
||||
if (window != null) {
|
||||
final RelativePoint point = new RelativePoint(window, new Point(0, 0));
|
||||
if (p.getScreenPoint().getX() - point.getScreenPoint().getX() < 40) { // triangle + offsets is ~40px
|
||||
p.getPoint().x += 40;
|
||||
}
|
||||
}
|
||||
balloon.show(p, Balloon.Position.below);
|
||||
}
|
||||
|
||||
BreakpointsMasterDetailPopupFactory.getInstance(project).setBalloonToHide(balloon, breakpoint);
|
||||
|
||||
@@ -322,6 +322,14 @@ public class XDebuggerTestUtil {
|
||||
return breakpoint.get();
|
||||
}
|
||||
|
||||
public static void removeAllBreakpoints(@NotNull final Project project) {
|
||||
final XBreakpointManager breakpointManager = XDebuggerManager.getInstance(project).getBreakpointManager();
|
||||
XBreakpoint<?>[] breakpoints = breakpointManager.getAllBreakpoints();
|
||||
for (XBreakpoint b: breakpoints) {
|
||||
breakpointManager.removeBreakpoint(b);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setBreakpointCondition(Project project, int line, final String condition) {
|
||||
XBreakpointManager breakpointManager = XDebuggerManager.getInstance(project).getBreakpointManager();
|
||||
for (XBreakpoint breakpoint : breakpointManager.getAllBreakpoints()) {
|
||||
|
||||
Reference in New Issue
Block a user