Merge remote-tracking branch 'origin/master'

This commit is contained in:
Roman Shevchenko
2015-10-02 20:54:34 +02:00
15 changed files with 201 additions and 52 deletions
@@ -15,22 +15,27 @@
*/
package com.intellij.execution.scratch;
import com.intellij.execution.application.ApplicationConfigurable;
import com.intellij.execution.application.ApplicationConfiguration;
import com.intellij.application.options.ModulesComboBox;
import com.intellij.execution.ui.CommonJavaParametersPanel;
import com.intellij.execution.ui.ConfigurationModuleSelector;
import com.intellij.execution.ui.DefaultJreSelector;
import com.intellij.execution.ui.JrePathEditor;
import com.intellij.ide.scratch.ScratchFileService;
import com.intellij.ide.scratch.ScratchRootType;
import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.LabeledComponent;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileWithId;
import com.intellij.ui.components.JBLabel;
import com.intellij.util.ui.components.BorderLayoutPanel;
import com.intellij.ui.PanelWithAnchor;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -43,13 +48,28 @@ import java.awt.event.ActionListener;
* @author Eugene Zhuravlev
* Date: 30-Sep-15
*/
public class JavaScratchConfigurable extends ApplicationConfigurable{
public class JavaScratchConfigurable extends SettingsEditor<JavaScratchConfiguration> implements PanelWithAnchor {
private final TextFieldWithBrowseButton myScratchPathField;
private final CommonJavaParametersPanel myCommonProgramParameters;
private final LabeledComponent<JTextField> myMainClass;
private final LabeledComponent<TextFieldWithBrowseButton> myScratchPathField;
private final LabeledComponent<ModulesComboBox> myModule;
private JPanel myWholePanel;
private final ConfigurationModuleSelector myModuleSelector;
private JrePathEditor myJrePathEditor;
private JComponent myAnchor;
public JavaScratchConfigurable(final Project project) {
super(project);
myScratchPathField = new TextFieldWithBrowseButton(new ActionListener() {
myMainClass = new LabeledComponent<JTextField>();
myMainClass.setLabelLocation(BorderLayout.WEST);
myMainClass.setText("Main &class:");
myMainClass.setComponent(new JTextField());
myScratchPathField = new LabeledComponent<TextFieldWithBrowseButton>();
myScratchPathField.setLabelLocation(BorderLayout.WEST);
myScratchPathField.setText("&Path to scratch file:");
myScratchPathField.setComponent(new TextFieldWithBrowseButton(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
VirtualFile toSelect = getVFileFromEditor();
@@ -63,33 +83,64 @@ public class JavaScratchConfigurable extends ApplicationConfigurable{
setVFileToEditor(file);
}
}
}, this);
}, this));
myModule = new LabeledComponent<ModulesComboBox>();
myModule.setLabelLocation(BorderLayout.WEST);
myModule.setComponent(new ModulesComboBox());
myModule.setText("Use classpath of &module:");
myModuleSelector = new ConfigurationModuleSelector(project, myModule.getComponent());
myCommonProgramParameters = new CommonJavaParametersPanel();
myCommonProgramParameters.setModuleContext(myModuleSelector.getModule());
myModule.getComponent().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
myCommonProgramParameters.setModuleContext(myModuleSelector.getModule());
}
});
myJrePathEditor = new JrePathEditor();
myJrePathEditor.setDefaultJreSelector(DefaultJreSelector.projectSdk(project));
myWholePanel = new JPanel(new GridBagLayout());
myWholePanel.add(myMainClass, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(6, 0, 0, 0),0, 0 ));
myWholePanel.add(myScratchPathField, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(6, 0, 0, 0),0, 0 ));
myWholePanel.add(myCommonProgramParameters, new GridBagConstraints(GridBagConstraints.RELATIVE, 2, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(12, 0, 12, 0),0, 0 ));
myWholePanel.add(myModule, new GridBagConstraints(GridBagConstraints.RELATIVE, 3, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),0, 0 ));
myWholePanel.add(myJrePathEditor, new GridBagConstraints(GridBagConstraints.RELATIVE, 4, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(6, 0, 0, 0),0, 0 ));
myAnchor = UIUtil.mergeComponentsWithAnchor(myMainClass, myScratchPathField, myCommonProgramParameters, myJrePathEditor, myModule);
}
@Override
public void applyEditorTo(ApplicationConfiguration configuration) throws ConfigurationException {
super.applyEditorTo(configuration);
public void applyEditorTo(JavaScratchConfiguration configuration) throws ConfigurationException {
myCommonProgramParameters.applyTo(configuration);
myModuleSelector.applyTo(configuration);
configuration.MAIN_CLASS_NAME = myMainClass.getComponent().getText().trim();
configuration.ALTERNATIVE_JRE_PATH = myJrePathEditor.getJrePathOrName();
configuration.ALTERNATIVE_JRE_PATH_ENABLED = myJrePathEditor.isAlternativeJreSelected();
final VirtualFile vFile = getVFileFromEditor();
((JavaScratchConfiguration)configuration).SCRATCH_FILE_ID = vFile instanceof VirtualFileWithId ? ((VirtualFileWithId)vFile).getId() : 0;
configuration.SCRATCH_FILE_ID = vFile instanceof VirtualFileWithId ? ((VirtualFileWithId)vFile).getId() : 0;
}
@Nullable
private VirtualFile getVFileFromEditor() {
final String path = FileUtil.toSystemIndependentName(myScratchPathField.getText());
final String path = FileUtil.toSystemIndependentName(myScratchPathField.getComponent().getText().trim());
return !StringUtil.isEmpty(path) ? LocalFileSystem.getInstance().findFileByPath(path) : null;
}
@Override
public void resetEditorFrom(ApplicationConfiguration configuration) {
super.resetEditorFrom(configuration);
final JavaScratchConfiguration scratchConfig = (JavaScratchConfiguration)configuration;
final VirtualFile file = scratchConfig.getScratchVirtualFile();
setVFileToEditor(file);
public void resetEditorFrom(JavaScratchConfiguration configuration) {
myCommonProgramParameters.reset(configuration);
myModuleSelector.reset(configuration);
myMainClass.getComponent().setText(configuration.MAIN_CLASS_NAME != null ? configuration.MAIN_CLASS_NAME.replaceAll("\\$", "\\.") : "");
myJrePathEditor.setPathOrName(configuration.ALTERNATIVE_JRE_PATH, configuration.ALTERNATIVE_JRE_PATH_ENABLED);
setVFileToEditor(configuration.getScratchVirtualFile());
}
private void setVFileToEditor(VirtualFile file) {
if (file != null) {
myScratchPathField.setText(FileUtil.toSystemDependentName(file.getPath()));
myScratchPathField.getComponent().setText(FileUtil.toSystemDependentName(file.getPath()));
}
else {
myScratchPathField.setText("");
@@ -99,9 +150,21 @@ public class JavaScratchConfigurable extends ApplicationConfigurable{
@NotNull
@Override
public JComponent createEditor() {
final JPanel panel = new JPanel(new GridBagLayout());
panel.add(new JBLabel("Path to scratch file: "), new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(20,0,0,10), 0, 0));
panel.add(myScratchPathField, new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(20, 0, 0, 0), 0, 0));
return new BorderLayoutPanel().addToCenter(super.createEditor()).addToBottom(panel);
return myWholePanel;
}
@Override
public JComponent getAnchor() {
return myAnchor;
}
@Override
public void setAnchor(@Nullable JComponent anchor) {
myAnchor = anchor;
myMainClass.setAnchor(anchor);
myScratchPathField.setAnchor(anchor);
myCommonProgramParameters.setAnchor(anchor);
myJrePathEditor.setAnchor(anchor);
myModule.setAnchor(anchor);
}
}
@@ -84,9 +84,8 @@ public class JavaResolveCache {
PsiType type = isOverloadCheck ? null : myCalculatedTypes.get(expr);
if (type == null) {
final RecursionGuard.StackStamp dStackStamp = PsiDiamondType.ourDiamondGuard.markStack();
final RecursionGuard.StackStamp gStackStamp = PsiResolveHelper.ourGraphGuard.markStack();
type = f.fun(expr);
if (!dStackStamp.mayCacheNow() || !gStackStamp.mayCacheNow() || isOverloadCheck) {
if (!dStackStamp.mayCacheNow() || isOverloadCheck) {
return type;
}
if (type == null) type = TypeConversionUtil.NULL_TYPE;
@@ -1195,7 +1195,9 @@ public class InferenceSession {
}
}
finally {
LambdaUtil.ourFunctionTypes.set(null);
if (formula instanceof InputOutputConstraintFormula) {
LambdaUtil.getFunctionalTypeMap().remove(((InputOutputConstraintFormula)formula).getExpression());
}
}
return true;
}
@@ -157,7 +157,7 @@ public class CheckedExceptionCompatibilityConstraint extends InputOutputConstrai
}
@Override
protected PsiExpression getExpression() {
public PsiExpression getExpression() {
return myExpression;
}
@@ -30,7 +30,7 @@ import java.util.*;
*/
public abstract class InputOutputConstraintFormula implements ConstraintFormula {
protected abstract PsiExpression getExpression();
public abstract PsiExpression getExpression();
protected abstract PsiType getT();
protected abstract void setT(PsiType t);
protected abstract InputOutputConstraintFormula createSelfConstraint(PsiType type, PsiExpression expression);
@@ -0,0 +1,50 @@
package nise;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.Supplier;
class TypeTest {
public static void main(String[] args) {
assertThat(id(new Combiner<>(echo("A"), echo("B"), (str1, str2) ->
new StringBuilder(str1.length() + str2.length())
.append(str1)
.append(str2))).get(),
hasSameContentAs("AB"));
}
private static <R> Supplier<R> id(Supplier<R> s) {
return s;
}
private static <T> Supplier<T> echo(T s) {
return () -> s;
}
private static Predicate<CharSequence> hasSameContentAs(CharSequence seq) {
return charSequence -> charSequence.toString().equals(seq.toString());
}
private static <T> void assertThat(T actual, Predicate<? super T> matcher) {
if (!matcher.test(actual)) throw new AssertionError();
}
private static class Combiner<T1, T2, R> implements Supplier<R> {
private final Supplier<T1> s1;
private final Supplier<T2> s2;
private final BiFunction<T1, T2, R> f;
public Combiner(Supplier<T1> s1, Supplier<T2> s2, BiFunction<T1, T2, R> f) {
this.s1 = s1;
this.s2 = s2;
this.f = f;
}
@Override
public R get() {
return f.apply(s1.get(), s2.get());
}
}
}
@@ -0,0 +1,25 @@
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
class Test {
void f(Stream<ReviewDiffRecord> stream1) {
final Supplier<List<String>> revisionDiffItemDTOs = () -> stream1.map(record -> {
foo(null);
final Object stream = record.getAllNodes().stream();
return "";
}).collect(Collectors.toList());
}
private <T> void foo(T t) throws RuntimeException {}
private class ReviewDiffRecord {
List<String> getAllNodes() {
return null;
}
}
}
@@ -46,6 +46,10 @@ public class Diamond8HighlightingTest extends LightDaemonAnalyzerTestCase {
public void testWithConstructorRefInside() throws Exception {
doTest();
}
public void testIDEA140686() throws Exception {
doTest();
}
private void doTest() throws Exception {
doTest(BASE_PATH + "/" + getTestName(false) + ".java", false, false);
@@ -16,17 +16,13 @@
package com.intellij.codeInsight.daemon.lambda;
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.testFramework.IdeaTestUtil;
import org.jetbrains.annotations.NonNls;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class Java8ExpressionsCheckTest extends LightDaemonAnalyzerTestCase {
@NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/lambda/expressions";
@@ -47,6 +43,10 @@ public class Java8ExpressionsCheckTest extends LightDaemonAnalyzerTestCase {
doTestAllMethodCallExpressions();
}
public void testProoveThatInferenceInsideLambdaBodyDontInfluenceOuterCallInference() throws Exception {
doTestAllMethodCallExpressions();
}
public void testCachedUnresolvedMethods() throws Exception {
doTestCachedUnresolved();
}
@@ -274,7 +274,6 @@ public class LivePreviewController implements LivePreview.Delegate, FindUtil.Rep
public void dispose() {
if (myDisposed) return;
myLivePreview.cleanUp();
off();
mySearchResults.dispose();
@@ -46,4 +46,8 @@ public abstract class ScratchFileService {
@NotNull
public abstract PerFileMappings<Language> getScratchesMapping();
public static boolean isInScratchRoot(@Nullable VirtualFile file) {
return getInstance().getRootType(file) != null;
}
}
@@ -22,9 +22,9 @@ import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.refactoring.move.MoveCallback;
import com.intellij.refactoring.move.MoveHandlerDelegate;
import org.jetbrains.annotations.Nullable;
@@ -62,13 +62,7 @@ public class MoveFilesOrDirectoriesHandler extends MoveHandlerDelegate {
public static boolean isValidTarget(PsiElement psiElement) {
if (!(psiElement instanceof PsiDirectory || psiElement instanceof PsiDirectoryContainer)) return false;
return psiElement.getManager().isInProject(psiElement) || isInScratches(psiElement);
}
protected static boolean isInScratches(PsiElement psiElement) {
VirtualFile virtualFile = psiElement instanceof PsiFileSystemItem ? ((PsiFileSystemItem)psiElement).getVirtualFile() : null;
if (virtualFile != null && ScratchFileService.getInstance().getRootType(virtualFile) != null) return true;
return false;
return psiElement.getManager().isInProject(psiElement) || ScratchFileService.isInScratchRoot(PsiUtilCore.getVirtualFile(psiElement));
}
public void doMove(final PsiElement[] elements, final PsiElement targetContainer) {
@@ -300,7 +300,10 @@ public class RenameProcessor extends BaseRefactoringProcessor {
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < elements.size(); i++) {
PsiElement element = elements.get(i);
LOG.assertTrue(element != null);
if (element == null) {
LOG.error("primary: " + myPrimaryElement + "; renamers: " + myRenamers);
continue;
}
final String newName = myAllRenames.get(element);
final UsageInfo[] usages = RenameUtil.findUsages(element, newName, mySearchInComments, mySearchTextOccurrences, myAllRenames);
final List<UsageInfo> usagesList = Arrays.asList(usages);
@@ -32,6 +32,7 @@ import com.intellij.ui.HyperlinkLabel;
import com.intellij.ui.TextFieldWithHistory;
import com.intellij.ui.TextFieldWithHistoryWithBrowseButton;
import com.intellij.util.NotNullProducer;
import com.intellij.util.ObjectUtils;
import com.intellij.util.PlatformIcons;
import com.intellij.util.containers.ComparatorUtil;
import com.intellij.util.containers.ContainerUtil;
@@ -295,7 +296,7 @@ public class SwingHelper {
boolean mergeWithPrevHistory) {
Set<String> newHistorySet = ContainerUtil.newHashSet(history);
List<String> prevHistory = textFieldWithHistory.getHistory();
List<String> mergedHistory = ContainerUtil.newArrayList();
List<String> mergedHistory = ContainerUtil.newArrayListWithCapacity(history.size());
if (mergeWithPrevHistory) {
for (String item : prevHistory) {
if (!newHistorySet.contains(item)) {
@@ -303,15 +304,20 @@ public class SwingHelper {
}
}
}
else {
String currentText = textFieldWithHistory.getText();
if (StringUtil.isNotEmpty(currentText) && !newHistorySet.contains(currentText)) {
mergedHistory.add(currentText);
}
}
mergedHistory.addAll(history);
String oldText = StringUtil.notNullize(textFieldWithHistory.getText());
String oldSelectedItem = ObjectUtils.tryCast(textFieldWithHistory.getSelectedItem(), String.class);
if (!mergedHistory.contains(oldSelectedItem)) {
oldSelectedItem = null;
}
textFieldWithHistory.setHistory(mergedHistory);
setLongestAsPrototype(textFieldWithHistory, mergedHistory);
if (oldSelectedItem != null) {
textFieldWithHistory.setSelectedItem(oldSelectedItem);
}
if (!oldText.equals(oldSelectedItem)) {
textFieldWithHistory.setText(oldText);
}
}
private static void setLongestAsPrototype(@NotNull JComboBox comboBox, @NotNull List<String> variants) {
@@ -23,7 +23,7 @@ import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.ide.fileTemplates.FileTemplate;
import com.intellij.ide.fileTemplates.FileTemplateManager;
import com.intellij.ide.scratch.ScratchRootType;
import com.intellij.ide.scratch.ScratchFileService;
import com.intellij.injected.editor.VirtualFileWindow;
import com.intellij.lang.ASTFactory;
import com.intellij.lang.ASTNode;
@@ -55,6 +55,7 @@ import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.psi.util.QualifiedName;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.util.*;
@@ -1832,8 +1833,7 @@ public class PyUtil {
}
public static boolean isInScratchFile(@NotNull PsiElement element) {
PsiFile file = element.getContainingFile();
return file != null && ScratchRootType.getInstance().isScratchFile(file.getVirtualFile());
return ScratchFileService.isInScratchRoot(PsiUtilCore.getVirtualFile(element));
}
/**