locationsOfLine(@NotNull ReferenceType type, @NotNull SourcePosition position) {
+ VirtualFile file = position.getFile().getVirtualFile();
+ if (file != null) {
+ int[] data = file.getUserData(LINE_NUMBERS_MAPPING_KEY);
+ if (data != null) {
+ int line = mapToOriginalLine(position.getLine() + 1, data);
+ if (line > -1) {
+ position = SourcePosition.createFromLine(position.getFile(), line - 1);
+ }
+ }
+ }
+
for (PositionManager positionManager : myPositionManagers) {
try {
return positionManager.locationsOfLine(type, position);
diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/PositionManagerImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/PositionManagerImpl.java
index 44337a6f1ee3..c58e7770d449 100644
--- a/java/debugger/impl/src/com/intellij/debugger/engine/PositionManagerImpl.java
+++ b/java/debugger/impl/src/com/intellij/debugger/engine/PositionManagerImpl.java
@@ -140,7 +140,7 @@ public class PositionManagerImpl implements PositionManager {
lineNumber = -1;
}
- if (psiFile instanceof PsiCompiledElement && lineNumber > -1) {
+ if (lineNumber > -1) {
VirtualFile file = psiFile.getVirtualFile();
if (file != null) {
int[] data = file.getUserData(LINE_NUMBERS_MAPPING_KEY);
diff --git a/java/debugger/impl/src/com/intellij/debugger/settings/IconObjectRenderer.java b/java/debugger/impl/src/com/intellij/debugger/settings/IconObjectRenderer.java
index 02fa84ef4f2c..26ddb3ff8155 100644
--- a/java/debugger/impl/src/com/intellij/debugger/settings/IconObjectRenderer.java
+++ b/java/debugger/impl/src/com/intellij/debugger/settings/IconObjectRenderer.java
@@ -23,8 +23,8 @@ import com.intellij.debugger.ui.impl.watch.ValueDescriptorImpl;
import com.intellij.debugger.ui.tree.ValueDescriptor;
import com.intellij.debugger.ui.tree.render.CompoundReferenceRenderer;
import com.intellij.debugger.ui.tree.render.DescriptorLabelListener;
+import com.intellij.icons.AllIcons;
import com.intellij.ui.components.JBLabel;
-import com.intellij.util.IconUtil;
import com.intellij.xdebugger.frame.XFullValueEvaluator;
import org.jetbrains.annotations.NotNull;
@@ -52,11 +52,8 @@ class IconObjectRenderer extends CompoundReferenceRenderer implements FullValueE
@Override
public Icon calcValueIcon(ValueDescriptor descriptor, EvaluationContext evaluationContext, DescriptorLabelListener listener)
throws EvaluateException {
- ImageIcon icon = ImageObjectRenderer.getIcon(evaluationContext, descriptor.getValue(), "iconToBytes");
- if (icon != null) {
- return IconUtil.cropIcon(icon, 16, 16);
- }
- return null;
+ String getterName = AllIcons.Debugger.Value.getIconHeight() <= 16 ? "iconToBytesPreviewNormal" : "iconToBytesPreviewRetina";
+ return ImageObjectRenderer.getIcon(evaluationContext, descriptor.getValue(), getterName);
}
@NotNull
diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaLineBreakpointTypeBase.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaLineBreakpointTypeBase.java
index 7427f91df500..8f092e26975b 100644
--- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaLineBreakpointTypeBase.java
+++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaLineBreakpointTypeBase.java
@@ -15,6 +15,7 @@
*/
package com.intellij.debugger.ui.breakpoints;
+import com.intellij.debugger.PositionManager;
import com.intellij.debugger.engine.DebuggerUtils;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileEditor.FileDocumentManager;
@@ -81,8 +82,8 @@ public abstract class JavaLineBreakpointTypeBase comments = PsiTreeUtil.findChildrenOfType(body, PsiComment.class);
+ for (PsiComment comment : comments) {
+ if (!PsiTreeUtil.isAncestor(psiExpression, comment, true)) {
+ return true;
+ }
+ }
+ return false;
+ }
};
}
diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java
index 496bd289247e..3face7908ec1 100644
--- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java
+++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java
@@ -20,6 +20,7 @@ import com.intellij.codeInspection.dataFlow.instructions.*;
import com.intellij.codeInspection.dataFlow.value.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Condition;
+import com.intellij.openapi.util.registry.Registry;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.tree.IElementType;
@@ -100,7 +101,9 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
addInstruction(new ReturnInstruction(false, null));
- new LiveVariablesAnalyzer(myCurrentFlow, myFactory).flushDeadVariablesOnStatementFinish();
+ if (Registry.is("idea.dfa.live.variables.analysis")) {
+ new LiveVariablesAnalyzer(myCurrentFlow, myFactory).flushDeadVariablesOnStatementFinish();
+ }
return myCurrentFlow;
}
diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowRunner.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowRunner.java
index 6db340c5ea10..6eeb6414ff22 100644
--- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowRunner.java
+++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowRunner.java
@@ -222,24 +222,11 @@ public class DataFlowRunner {
protected DfaInstructionState[] acceptInstruction(InstructionVisitor visitor, DfaInstructionState instructionState) {
Instruction instruction = instructionState.getInstruction();
- if (instruction instanceof MethodCallInstruction) {
- PsiCallExpression anchor = ((MethodCallInstruction)instruction).getCallExpression();
- if (anchor instanceof PsiNewExpression) {
- PsiAnonymousClass anonymousClass = ((PsiNewExpression)anchor).getAnonymousClass();
- if (anonymousClass != null) {
- registerNestedClosures(instructionState, anonymousClass);
- }
- }
- }
- else if (instruction instanceof LambdaInstruction) {
- PsiLambdaExpression lambdaExpression = ((LambdaInstruction)instruction).getLambdaExpression();
- registerNestedClosures(instructionState, lambdaExpression);
- }
- else if (instruction instanceof EmptyInstruction) {
- PsiElement anchor = ((EmptyInstruction)instruction).getAnchor();
- if (anchor instanceof PsiClass) {
- registerNestedClosures(instructionState, (PsiClass)anchor);
- }
+ PsiElement closure = DfaUtil.getClosureInside(instruction);
+ if (closure instanceof PsiClass) {
+ registerNestedClosures(instructionState, (PsiClass)closure);
+ } else if (closure instanceof PsiLambdaExpression) {
+ registerNestedClosures(instructionState, (PsiLambdaExpression)closure);
}
return instruction.accept(this, instructionState.getMemoryState(), visitor);
diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaUtil.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaUtil.java
index d147c270c1c5..6bb70010c9ca 100644
--- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaUtil.java
+++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaUtil.java
@@ -15,9 +15,7 @@
*/
package com.intellij.codeInspection.dataFlow;
-import com.intellij.codeInspection.dataFlow.instructions.AssignInstruction;
-import com.intellij.codeInspection.dataFlow.instructions.Instruction;
-import com.intellij.codeInspection.dataFlow.instructions.PushInstruction;
+import com.intellij.codeInspection.dataFlow.instructions.*;
import com.intellij.codeInspection.dataFlow.value.DfaValue;
import com.intellij.codeInspection.dataFlow.value.DfaVariableValue;
import com.intellij.openapi.util.MultiValuesMap;
@@ -113,6 +111,26 @@ public class DfaUtil {
return Collections.emptyList();
}
+ @Nullable
+ static PsiElement getClosureInside(Instruction instruction) {
+ if (instruction instanceof MethodCallInstruction) {
+ PsiCallExpression anchor = ((MethodCallInstruction)instruction).getCallExpression();
+ if (anchor instanceof PsiNewExpression) {
+ return ((PsiNewExpression)anchor).getAnonymousClass();
+ }
+ }
+ else if (instruction instanceof LambdaInstruction) {
+ return ((LambdaInstruction)instruction).getLambdaExpression();
+ }
+ else if (instruction instanceof EmptyInstruction) {
+ PsiElement anchor = ((EmptyInstruction)instruction).getAnchor();
+ if (anchor instanceof PsiClass) {
+ return anchor;
+ }
+ }
+ return null;
+ }
+
private static class ValuableInstructionVisitor extends StandardInstructionVisitor {
final Map myResults = ContainerUtil.newHashMap();
diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/LiveVariablesAnalyzer.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/LiveVariablesAnalyzer.java
index 55709d71ca49..937caa84e24d 100644
--- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/LiveVariablesAnalyzer.java
+++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/LiveVariablesAnalyzer.java
@@ -21,10 +21,11 @@ import com.intellij.codeInspection.dataFlow.value.DfaValueFactory;
import com.intellij.codeInspection.dataFlow.value.DfaVariableValue;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.util.Pair;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiRecursiveElementWalkingVisitor;
+import com.intellij.psi.PsiReferenceExpression;
import com.intellij.util.PairFunction;
-import com.intellij.util.containers.ContainerUtil;
-import com.intellij.util.containers.FilteringIterator;
-import com.intellij.util.containers.MultiMap;
+import com.intellij.util.containers.*;
import com.intellij.util.containers.Queue;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -39,6 +40,26 @@ public class LiveVariablesAnalyzer {
private final Instruction[] myInstructions;
private final MultiMap myForwardMap;
private final MultiMap myBackwardMap;
+ @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") private final FactoryMap> myClosureReads = new FactoryMap>() {
+ @Nullable
+ @Override
+ protected List create(PsiElement closure) {
+ final Set result = ContainerUtil.newLinkedHashSet();
+ closure.accept(new PsiRecursiveElementWalkingVisitor() {
+ @Override
+ public void visitElement(PsiElement element) {
+ if (element instanceof PsiReferenceExpression) {
+ DfaValue value = myFactory.createValue((PsiReferenceExpression)element);
+ if (value instanceof DfaVariableValue) {
+ result.add((DfaVariableValue)value);
+ }
+ }
+ super.visitElement(element);
+ }
+ });
+ return ContainerUtil.newArrayList(result);
+ }
+ };
public LiveVariablesAnalyzer(ControlFlow flow, DfaValueFactory factory) {
myFactory = factory;
@@ -96,12 +117,36 @@ public class LiveVariablesAnalyzer {
return result;
}
+ @Nullable
+ private static DfaVariableValue getWrittenVariable(Instruction instruction) {
+ if (instruction instanceof AssignInstruction) {
+ DfaValue value = ((AssignInstruction)instruction).getAssignedValue();
+ return value instanceof DfaVariableValue ? (DfaVariableValue)value : null;
+ }
+ if (instruction instanceof FlushVariableInstruction) return ((FlushVariableInstruction)instruction).getVariable();
+ return null;
+ }
+
+ @NotNull
+ private List getReadVariables(Instruction instruction) {
+ if (instruction instanceof PushInstruction && !((PushInstruction)instruction).isReferenceWrite()) {
+ DfaValue value = ((PushInstruction)instruction).getValue();
+ if (value instanceof DfaVariableValue) {
+ return Collections.singletonList((DfaVariableValue)value);
+ }
+ } else {
+ PsiElement closure = DfaUtil.getClosureInside(instruction);
+ if (closure != null) {
+ return myClosureReads.get(closure);
+ }
+ }
+ return Collections.emptyList();
+ }
+
private boolean isInterestingInstruction(Instruction instruction) {
if (instruction == myInstructions[0]) return true;
- if (instruction instanceof PushInstruction) return ((PushInstruction)instruction).getValue() instanceof DfaVariableValue;
- if (instruction instanceof AssignInstruction) return ((AssignInstruction)instruction).getAssignedValue() != null;
+ if (!getReadVariables(instruction).isEmpty() || getWrittenVariable(instruction) != null) return true;
return instruction instanceof FinishElementInstruction ||
- instruction instanceof FlushVariableInstruction ||
instruction instanceof GotoInstruction ||
instruction instanceof ConditionalGotoInstruction ||
instruction instanceof ReturnInstruction;
@@ -124,34 +169,24 @@ public class LiveVariablesAnalyzer {
}
}
- if (instruction instanceof AssignInstruction) {
- DfaValue value = ((AssignInstruction)instruction).getAssignedValue();
- if (value instanceof DfaVariableValue) {
- liveVars = (BitSet)liveVars.clone();
- liveVars.clear(value.getID());
- for (DfaVariableValue var : myFactory.getVarFactory().getAllQualifiedBy((DfaVariableValue)value)) {
- liveVars.clear(var.getID());
- }
+ DfaVariableValue written = getWrittenVariable(instruction);
+ if (written != null) {
+ liveVars = (BitSet)liveVars.clone();
+ liveVars.clear(written.getID());
+ for (DfaVariableValue var : myFactory.getVarFactory().getAllQualifiedBy(written)) {
+ liveVars.clear(var.getID());
}
- }
-
- if (instruction instanceof PushInstruction) {
- DfaValue value = ((PushInstruction)instruction).getValue();
- if (value instanceof DfaVariableValue) {
- if (!((PushInstruction)instruction).isReferenceWrite() && !liveVars.get(value.getID())) {
- liveVars = (BitSet)liveVars.clone();
+ } else {
+ boolean cloned = false;
+ for (DfaVariableValue value : getReadVariables(instruction)) {
+ if (!liveVars.get(value.getID())) {
+ if (!cloned) {
+ liveVars = (BitSet)liveVars.clone();
+ cloned = true;
+ }
liveVars.set(value.getID());
}
}
- } else if (instruction instanceof FlushVariableInstruction) {
- DfaVariableValue variable = ((FlushVariableInstruction)instruction).getVariable();
- if (variable != null) {
- liveVars = (BitSet)liveVars.clone();
- liveVars.clear(variable.getID());
- for (DfaVariableValue var : myFactory.getVarFactory().getAllQualifiedBy(variable)) {
- liveVars.clear(var.getID());
- }
- }
}
return liveVars;
diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorParameterFromFieldFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorParameterFromFieldFix.java
index 12cf5d8aae2f..5f2a00d6a18a 100644
--- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorParameterFromFieldFix.java
+++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorParameterFromFieldFix.java
@@ -144,7 +144,9 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction {
}
for (PsiMethodMember member : elements) {
- if (!addParameterToConstructor(project, file, editor, member.getElement(), new PsiField[] {getField()}, cleanupElements)) break;
+ if (!addParameterToConstructor(project, file, editor, member.getElement(), new PsiField[] {getField()}, cleanupElements)) {
+ break;
+ }
}
} else if (!constrs.isEmpty()) {
@@ -317,9 +319,9 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction {
assert constructor != null;
PsiParameter[] newParameters = constructor.getParameterList().getParameters();
if (newParameters == parameters) return false; //user must have canceled dialog
- boolean created = false;
// do not introduce assignment in chanined constructor
if (JavaHighlightUtil.getChainedConstructors(constructor) == null) {
+ boolean created = false;
for (PsiField field : fields.keySet()) {
final String defaultParamName = fields.get(field);
PsiParameter parameter = findParamByName(defaultParamName, field.getType(), newParameters, parameterInfos);
@@ -334,8 +336,10 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction {
}
created = true;
}
+ return created;
+ } else {
+ return true;
}
- return created;
}
private static void notNull(PsiField field, PsiParameter parameter) {
diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/GenerateDelegateHandler.java b/java/java-impl/src/com/intellij/codeInsight/generation/GenerateDelegateHandler.java
index fe4208deada7..9ec8d1a32f84 100644
--- a/java/java-impl/src/com/intellij/codeInsight/generation/GenerateDelegateHandler.java
+++ b/java/java-impl/src/com/intellij/codeInsight/generation/GenerateDelegateHandler.java
@@ -106,7 +106,7 @@ public class GenerateDelegateHandler implements LanguageCodeInsightActionHandler
}
private PsiGenerationInfo generateDelegatePrototype(PsiMethodMember methodCandidate, PsiElement target) throws IncorrectOperationException {
- PsiMethod method = GenerateMembersUtil.substituteGenericMethod(methodCandidate.getElement(), methodCandidate.getSubstitutor());
+ PsiMethod method = GenerateMembersUtil.substituteGenericMethod(methodCandidate.getElement(), methodCandidate.getSubstitutor(), target);
clearMethod(method);
clearModifiers(method);
diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersUtil.java b/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersUtil.java
index 936f587d5fb7..9c9034dc7e94 100644
--- a/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersUtil.java
+++ b/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersUtil.java
@@ -475,7 +475,7 @@ public class GenerateMembersUtil {
if (method.isConstructor()) {
return factory.createConstructor(method.getName(), target);
}
- return factory.createMethod(method.getName(), PsiType.VOID);
+ return factory.createMethod(method.getName(), PsiType.VOID, target);
}
private static void substituteReturnType(@NotNull PsiManager manager,
diff --git a/java/java-impl/src/com/intellij/psi/impl/JavaRegExpHost.java b/java/java-impl/src/com/intellij/psi/impl/JavaRegExpHost.java
index 21a03d7e2bc3..daf6501443df 100644
--- a/java/java-impl/src/com/intellij/psi/impl/JavaRegExpHost.java
+++ b/java/java-impl/src/com/intellij/psi/impl/JavaRegExpHost.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
@@ -21,12 +21,16 @@ import com.intellij.openapi.projectRoots.JavaSdk;
import com.intellij.openapi.projectRoots.JavaSdkVersion;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ModuleRootManager;
+import com.intellij.psi.PsiElement;
import org.intellij.lang.regexp.DefaultRegExpPropertiesProvider;
import org.intellij.lang.regexp.RegExpLanguageHost;
+import org.intellij.lang.regexp.psi.RegExpChar;
import org.intellij.lang.regexp.psi.RegExpGroup;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import java.util.regex.Pattern;
+
/**
* @author yole
*/
@@ -60,19 +64,31 @@ public class JavaRegExpHost implements RegExpLanguageHost {
@Override
public boolean supportsNamedGroupSyntax(RegExpGroup group) {
- if (group.isRubyNamedGroup()) {
- final Module module = ModuleUtilCore.findModuleForPsiElement(group);
- if (module != null) {
- final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
- if (sdk != null && sdk.getSdkType() instanceof JavaSdk) {
- final JavaSdkVersion version = JavaSdk.getInstance().getVersion(sdk);
- return version != null && version.isAtLeast(JavaSdkVersion.JDK_1_7);
- }
- }
+ if (group.isNamedGroup()) {
+ final JavaSdkVersion version = getJavaVersion(group);
+ return version != null && version.isAtLeast(JavaSdkVersion.JDK_1_7);
}
return false;
}
+ @Override
+ public boolean supportsExtendedHexCharacter(RegExpChar regExpChar) {
+ final JavaSdkVersion version = getJavaVersion(regExpChar);
+ return version != null && version.isAtLeast(JavaSdkVersion.JDK_1_7);
+ }
+
+ @Nullable
+ private static JavaSdkVersion getJavaVersion(PsiElement element) {
+ final Module module = ModuleUtilCore.findModuleForPsiElement(element);
+ if (module != null) {
+ final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
+ if (sdk != null && sdk.getSdkType() instanceof JavaSdk) {
+ return JavaSdk.getInstance().getVersion(sdk);
+ }
+ }
+ return null;
+ }
+
@Override
public boolean isValidCategory(@NotNull String category) {
return myPropertiesProvider.isValidCategory(category);
diff --git a/java/java-impl/src/com/intellij/refactoring/actions/RenameFileAction.java b/java/java-impl/src/com/intellij/refactoring/actions/RenameFileAction.java
index d4a8d8398045..651474f94037 100644
--- a/java/java-impl/src/com/intellij/refactoring/actions/RenameFileAction.java
+++ b/java/java-impl/src/com/intellij/refactoring/actions/RenameFileAction.java
@@ -42,7 +42,8 @@ public class RenameFileAction extends AnAction implements DumbAware {
public void update(AnActionEvent e) {
PsiFile file = e.getData(CommonDataKeys.PSI_FILE);
Presentation presentation = e.getPresentation();
- boolean enabled = file instanceof PsiClassOwner && e.getPlace() != ActionPlaces.EDITOR_POPUP && e.getData(CommonDataKeys.PROJECT) != null;
+ String place = e.getPlace();
+ boolean enabled = (file instanceof PsiClassOwner || ActionPlaces.EDITOR_TAB_POPUP.equals(place)) && place != ActionPlaces.EDITOR_POPUP && e.getData(CommonDataKeys.PROJECT) != null;
presentation.setEnabled(enabled);
presentation.setVisible(enabled);
if (enabled) {
diff --git a/java/java-impl/src/com/intellij/refactoring/invertBoolean/InvertBooleanProcessor.java b/java/java-impl/src/com/intellij/refactoring/invertBoolean/InvertBooleanProcessor.java
index 5ef2cabab9f1..df2efc6f4440 100644
--- a/java/java-impl/src/com/intellij/refactoring/invertBoolean/InvertBooleanProcessor.java
+++ b/java/java-impl/src/com/intellij/refactoring/invertBoolean/InvertBooleanProcessor.java
@@ -16,6 +16,7 @@
package com.intellij.refactoring.invertBoolean;
import com.intellij.codeInsight.CodeInsightServicesUtil;
+import com.intellij.codeInsight.daemon.impl.RecursiveCallLineMarkerProvider;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Ref;
@@ -139,7 +140,8 @@ public class InvertBooleanProcessor extends BaseRefactoringProcessor {
if (argumentList != null) {
final PsiExpression[] args = argumentList.getExpressions();
if (index < args.length) {
- if (methodExpression == null || methodExpression.getQualifier() == null || !"super".equals(methodExpression.getQualifierExpression().getText())) {
+ if (methodExpression == null ||
+ canInvert(methodExpression, args[index] instanceof PsiReferenceExpression && ((PsiReferenceExpression)args[index]).resolve() == myElement)) {
toInvert.add(mySmartPointerManager.createSmartPsiElementPointer(args[index]));
}
}
@@ -181,6 +183,19 @@ public class InvertBooleanProcessor extends BaseRefactoringProcessor {
return result.toArray(new UsageInfo[result.size()]);
}
+ private static boolean canInvert(PsiReferenceExpression methodExpression, boolean checkRecursive) {
+ PsiExpression qualifierExpression = methodExpression.getQualifierExpression();
+ if (qualifierExpression == null || !"super".equals(qualifierExpression.getText())) {
+ PsiElement parent = methodExpression.getParent();
+ if (parent instanceof PsiMethodCallExpression) {
+ return !(checkRecursive && RecursiveCallLineMarkerProvider.isRecursiveMethodCall((PsiMethodCallExpression)parent));
+ } else {
+ return true;
+ }
+ }
+ return false;
+ }
+
private void addRefsToInvert(final List toInvert, final PsiNamedElement namedElement) {
final Query query = namedElement instanceof PsiMethod ?
MethodReferencesSearch.search((PsiMethod)namedElement) :
@@ -197,9 +212,9 @@ public class InvertBooleanProcessor extends BaseRefactoringProcessor {
}
else {
if (namedElement instanceof PsiParameter) { //filter usages in super method calls
- if (refExpr.getParent().getParent() instanceof PsiMethodCallExpression) {
- final PsiReferenceExpression methodExpression = ((PsiMethodCallExpression)refExpr.getParent().getParent()).getMethodExpression();
- if (methodExpression.getQualifier() != null && "super".equals(methodExpression.getQualifierExpression().getText())) {
+ PsiElement gParent = refExpr.getParent().getParent();
+ if (gParent instanceof PsiMethodCallExpression) {
+ if (!canInvert(((PsiMethodCallExpression)gParent).getMethodExpression(), true)) {
continue;
}
}
diff --git a/java/java-psi-api/src/com/intellij/psi/JVMElementFactory.java b/java/java-psi-api/src/com/intellij/psi/JVMElementFactory.java
index e6c38aa5a186..7c3999e37a7b 100644
--- a/java/java-psi-api/src/com/intellij/psi/JVMElementFactory.java
+++ b/java/java-psi-api/src/com/intellij/psi/JVMElementFactory.java
@@ -84,6 +84,9 @@ public interface JVMElementFactory {
@NotNull
PsiMethod createMethod(@NotNull @NonNls String name, PsiType returnType) throws IncorrectOperationException;
+ @NotNull
+ PsiMethod createMethod(@NotNull @NonNls String name, PsiType returnType, PsiElement context) throws IncorrectOperationException;
+
/**
* Creates an empty constructor.
*
diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java
index 0515b4983ce2..2163057032d8 100644
--- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java
+++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java
@@ -247,6 +247,12 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps
return (PsiMethod)CodeStyleManager.getInstance(myManager.getProject()).reformat(method);
}
+ @NotNull
+ @Override
+ public PsiMethod createMethod(@NotNull @NonNls String name, PsiType returnType, PsiElement context) throws IncorrectOperationException {
+ return createMethodFromText("public " + returnType.getCanonicalText(true) + " " + name + "() {}", context);
+ }
+
@NotNull
@Override
public PsiMethod createConstructor() {
diff --git a/java/java-runtime/src/com/intellij/rt/debugger/ImageSerializer.java b/java/java-runtime/src/com/intellij/rt/debugger/ImageSerializer.java
index 5b727483a0f9..ad38e2c87103 100644
--- a/java/java-runtime/src/com/intellij/rt/debugger/ImageSerializer.java
+++ b/java/java-runtime/src/com/intellij/rt/debugger/ImageSerializer.java
@@ -35,6 +35,21 @@ public class ImageSerializer {
return baos.toByteArray();
}
+ public static byte[] iconToBytesPreview(Icon icon, int maxSize) throws IOException {
+ if (icon.getIconHeight() <= maxSize && icon.getIconWidth() <= maxSize) {
+ return imageToBytes(toImage(icon));
+ }
+ return null;
+ }
+
+ public static byte[] iconToBytesPreviewNormal(Icon icon) throws IOException {
+ return iconToBytesPreview(icon, 16);
+ }
+
+ public static byte[] iconToBytesPreviewRetina(Icon icon) throws IOException {
+ return iconToBytesPreview(icon, 32);
+ }
+
public static byte[] iconToBytes(Icon icon) throws IOException {
return imageToBytes(toImage(icon));
}
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/IDEA131700.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/IDEA131700.java
new file mode 100644
index 000000000000..970305015f41
--- /dev/null
+++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/IDEA131700.java
@@ -0,0 +1,41 @@
+import java.util.Optional;
+import java.util.function.Function;
+
+class Scratch
+{
+ public static void main(String[] args) throws Exception
+ {
+ final Optional i = foo();
+ System.out.println(i);
+ }
+
+ private static Optional foo()
+ {
+ final Optional s = returnsR(
+ "foo",
+ z -> {
+ if (z.isEmpty())
+ {
+ return Optional.empty();
+ }
+ else
+ {
+ return Optional.of("a string");
+ }
+ });
+
+ if (s.isPresent())
+ {
+ return Optional.of(1);
+ }
+ else
+ {
+ return Optional.of(2);
+ }
+ }
+
+ private static R returnsR(String s, Function f)
+ {
+ return f.apply(s);
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/afterMultipleChainedConstructors.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/afterMultipleChainedConstructors.java
new file mode 100644
index 000000000000..f71c0f6e1dcd
--- /dev/null
+++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/afterMultipleChainedConstructors.java
@@ -0,0 +1,16 @@
+// "Add constructor parameter" "true"
+abstract class FooBar {
+ protected final String myFoo;
+
+ public FooBar(String myFoo) {
+ this.myFoo = myFoo;
+ }
+
+ public FooBar(Integer interestingType, String myFoo) {
+ this(myFoo);
+ }
+
+ public FooBar(int i, String myFoo) {
+ this(myFoo);
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/beforeMultipleChainedConstructors.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/beforeMultipleChainedConstructors.java
new file mode 100644
index 000000000000..705a3bfad74b
--- /dev/null
+++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createConstructorParameterFromField/beforeMultipleChainedConstructors.java
@@ -0,0 +1,15 @@
+// "Add constructor parameter" "true"
+abstract class FooBar {
+ protected final String myFoo;
+
+ public FooBar() {
+ }
+
+ public FooBar(Integer interestingType) {
+ this();
+ }
+
+ public FooBar(int i) {
+ this();
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/lambdaCodeBlock2Expr/afterCommentsInsideExpr.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/lambdaCodeBlock2Expr/afterCommentsInsideExpr.java
new file mode 100644
index 000000000000..2205522b62e4
--- /dev/null
+++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/lambdaCodeBlock2Expr/afterCommentsInsideExpr.java
@@ -0,0 +1,7 @@
+// "Replace with expression lambda" "true"
+class Test {
+ {
+ Runnable r = () -> System.out.println(""//todo comment
+ );
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/lambdaCodeBlock2Expr/beforeComments.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/lambdaCodeBlock2Expr/beforeComments.java
new file mode 100644
index 000000000000..d6731a471d4d
--- /dev/null
+++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/lambdaCodeBlock2Expr/beforeComments.java
@@ -0,0 +1,19 @@
+// "Replace with expression lambda" "false"
+class Test {
+ {
+ a(() -> {
+ //my comment here
+ return new Object(){};
+ });
+ }
+
+ void a(Supplier