From ad8fece5c07e1b9361be2596fc41aadb1410cf9d Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Thu, 5 Nov 2015 14:01:48 +0300 Subject: [PATCH 01/16] maven: expire unmanaged pom.xml notification if the pom.xml was added as managed file --- .../maven/project/MavenProjectsManager.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java index 4f219a262781..300f28e0e797 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java @@ -39,6 +39,7 @@ import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.*; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; @@ -569,13 +570,30 @@ public class MavenProjectsManager extends MavenSimpleProjectComponent myWatcher.resetManagedFilesAndProfilesInTests(files, profiles); } - public void addManagedFilesWithProfiles(List files, MavenExplicitProfiles profiles) { + public void addManagedFilesWithProfiles(final List files, MavenExplicitProfiles profiles) { if (!isInitialized()) { initNew(files, profiles); } else { myWatcher.addManagedFilesWithProfiles(files, profiles); } + + MavenUtil.invokeLater(myProject, new Runnable() { + @Override + public void run() { + if (myProject == null || !myProject.isDefault() && !myProject.isDisposed()) { + for (Notification notification : EventLog.getLogModel(myProject).getNotifications()) { + if (NON_MANAGED_POM_NOTIFICATION_GROUP_ID.equals(notification.getGroupId())) { + for (VirtualFile file : files) { + if (StringUtil.startsWith(notification.getContent(), file.getPresentableUrl())) { + notification.expire(); + } + } + } + } + } + } + }); } public void addManagedFiles(@NotNull List files) { From 952cdde6396af3a95f4509ac0f1cd35e985374a1 Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Thu, 5 Nov 2015 14:37:37 +0300 Subject: [PATCH 02/16] guava type migration: convert statically imported FluentIterable.from/of --- .../GuavaFluentIterableConversionRule.java | 19 ++++++++--- .../inspections/GuavaInspectionTest.java | 4 +++ ...entIterableWithStaticallyImportedFrom.java | 33 +++++++++++++++++++ ...rableWithStaticallyImportedFrom_after.java | 32 ++++++++++++++++++ 4 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 java/typeMigration/testData/inspections/guava/fluentIterableWithStaticallyImportedFrom.java create mode 100644 java/typeMigration/testData/inspections/guava/fluentIterableWithStaticallyImportedFrom_after.java diff --git a/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaFluentIterableConversionRule.java b/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaFluentIterableConversionRule.java index 20dd26270dc9..41f3b5fc97bc 100644 --- a/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaFluentIterableConversionRule.java +++ b/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaFluentIterableConversionRule.java @@ -91,8 +91,6 @@ public class GuavaFluentIterableConversionRule extends BaseGuavaTypeConversionRu } static { - DESCRIPTORS_MAP.put("of", new TypeConversionDescriptorFactory("FluentIterable.of($arr$)", "java.util.Arrays.stream($arr$)", false, true, true)); - DESCRIPTORS_MAP.put("isEmpty", new TypeConversionDescriptorFactory("$q$.isEmpty()", "$q$.findAny().isPresent()", false)); DESCRIPTORS_MAP.put("skip", new TypeConversionDescriptorFactory("$q$.skip($p$)", "$q$.skip($p$)", false, true, true)); DESCRIPTORS_MAP.put("limit", new TypeConversionDescriptorFactory("$q$.limit($p$)", "$q$.limit($p$)", false, true, true)); @@ -137,15 +135,26 @@ public class GuavaFluentIterableConversionRule extends BaseGuavaTypeConversionRu TypeConversionDescriptor descriptorBase = null; PsiType conversionType = null; boolean needSpecifyType = true; - if (methodName.equals("from")) { - descriptorBase = new TypeConversionDescriptor("FluentIterable.from($it$)", null) { + if (methodName.equals("of")) { + descriptorBase = new TypeConversionDescriptor(null, "java.util.Arrays.stream($arr$)") { @Override public PsiExpression replace(PsiExpression expression) { + setStringToReplace((((PsiMethodCallExpression)expression).getMethodExpression().getQualifierExpression() != null + ? "FluentIterable." : "") + "of($arr$)"); + return super.replace(expression); + } + }; + } else if (methodName.equals("from")) { + descriptorBase = new TypeConversionDescriptor(null, null) { + @Override + public PsiExpression replace(PsiExpression expression) { + final PsiMethodCallExpression methodCall = (PsiMethodCallExpression)expression; PsiExpression argument = - PseudoLambdaReplaceTemplate.replaceTypeParameters(((PsiMethodCallExpression)expression).getArgumentList().getExpressions()[0]); + PseudoLambdaReplaceTemplate.replaceTypeParameters(methodCall.getArgumentList().getExpressions()[0]); if (argument == null) { return expression; } + setStringToReplace((methodCall.getMethodExpression().getQualifierExpression() != null ? "FluentIterable." : "") + "from($it$)"); boolean isCollection = InheritanceUtil.isInheritor(PsiTypesUtil.getPsiClass(argument.getType()), CommonClassNames.JAVA_UTIL_COLLECTION); setReplaceByString(isCollection ? "$it$.stream()" : "java.util.stream.StreamSupport.stream($it$.spliterator(), false)"); diff --git a/java/typeMigration/test/com/intellij/codeInsight/inspections/GuavaInspectionTest.java b/java/typeMigration/test/com/intellij/codeInsight/inspections/GuavaInspectionTest.java index ce483d733347..285d54a50105 100644 --- a/java/typeMigration/test/com/intellij/codeInsight/inspections/GuavaInspectionTest.java +++ b/java/typeMigration/test/com/intellij/codeInsight/inspections/GuavaInspectionTest.java @@ -178,6 +178,10 @@ public class GuavaInspectionTest extends JavaCodeInsightFixtureTestCase { doTest(); } + public void testFluentIterableWithStaticallyImportedFrom() { + doTest(); + } + private void doTestNoQuickFixes(final Class... quickFixesClasses) { myFixture.configureByFile(getTestName(true) + ".java"); myFixture.enableInspections(new GuavaInspection()); diff --git a/java/typeMigration/testData/inspections/guava/fluentIterableWithStaticallyImportedFrom.java b/java/typeMigration/testData/inspections/guava/fluentIterableWithStaticallyImportedFrom.java new file mode 100644 index 000000000000..d3eaf1a6f61a --- /dev/null +++ b/java/typeMigration/testData/inspections/guava/fluentIterableWithStaticallyImportedFrom.java @@ -0,0 +1,33 @@ +import com.google.common.base.Function; +import com.google.common.collect.FluentIterable; +import static com.google.common.collect.FluentIterable.from + +import java.util.ArrayList; +import java.util.List; + +class A { + + Function myFunction = new Function() { + @Override + public String apply(String input) { + return input.trim(); + } + }; + + List main(String[] args) { + ArrayList strings = new ArrayList(); + FluentIterable it = from(strings); + it = it.transform(input -> input.intern()); + it = it.transform(String::trim); + it = it.transform(new Function() { + @Override + public String apply(String input) { + System.out.println("do some action on " + input); + return input.substring(0, 10); + } + }); + it = it.transform(myFunction); + return it.toList(); + } + +} \ No newline at end of file diff --git a/java/typeMigration/testData/inspections/guava/fluentIterableWithStaticallyImportedFrom_after.java b/java/typeMigration/testData/inspections/guava/fluentIterableWithStaticallyImportedFrom_after.java new file mode 100644 index 000000000000..4dcc7384d44d --- /dev/null +++ b/java/typeMigration/testData/inspections/guava/fluentIterableWithStaticallyImportedFrom_after.java @@ -0,0 +1,32 @@ +import com.google.common.base.Function; + +import static com.google.common.collect.FluentIterable.from + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +class A { + + Function myFunction = new Function() { + @Override + public String apply(String input) { + return input.trim(); + } + }; + + List main(String[] args) { + ArrayList strings = new ArrayList(); + Stream it = strings.stream(); + it = it.map(input -> input.intern()); + it = it.map(String::trim); + it = it.map(input -> { + System.out.println("do some action on " + input); + return input.substring(0, 10); + }); + it = it.map(myFunction::apply); + return it.collect(Collectors.toList()); + } + +} \ No newline at end of file From 618b2d6e108dc4b0869c37b054c876a62e4f9016 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 5 Nov 2015 12:36:08 +0100 Subject: [PATCH 03/16] log.info when IDE is both frozen and low on heap memory --- .../com/intellij/diagnostic/PerformanceWatcher.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/platform/core-impl/src/com/intellij/diagnostic/PerformanceWatcher.java b/platform/core-impl/src/com/intellij/diagnostic/PerformanceWatcher.java index e953bbff7c33..3d8e6cae5786 100644 --- a/platform/core-impl/src/com/intellij/diagnostic/PerformanceWatcher.java +++ b/platform/core-impl/src/com/intellij/diagnostic/PerformanceWatcher.java @@ -251,6 +251,8 @@ public class PerformanceWatcher implements ApplicationComponent { return null; } + checkMemoryUsage(file); + try { OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file)); try { @@ -272,6 +274,17 @@ public class PerformanceWatcher implements ApplicationComponent { return file; } + private static void checkMemoryUsage(File file) { + final Runtime rt = Runtime.getRuntime(); + final long allocatedMem = rt.totalMemory(); + final long unusedMem = rt.freeMemory(); + if (unusedMem < allocatedMem / 5) { + LOG.info("High memory usage (free " + (unusedMem / 1024 / 1024) + + " of " + (allocatedMem / 1024 / 1024) + + " MB) while dumping threads to " + file); + } + } + @SuppressWarnings("UseOfSystemOutOrSystemErr") public static void dumpThreadsToConsole(String message) { System.err.println(message); From 3d873661bde52430d1e20d9df14f4b27d7d5ba9a Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 5 Nov 2015 12:38:43 +0100 Subject: [PATCH 04/16] use a more comprehensive method name in JavaCompletionSorting (IDEA-CR-6172) --- .../codeInsight/completion/JavaCompletionSorting.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionSorting.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionSorting.java index 949590106a08..69b09f2035ad 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionSorting.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionSorting.java @@ -455,11 +455,11 @@ public class JavaCompletionSorting { ContainerUtil.addIfNotNull(myExpectedClasses, PsiUtil.substituteTypeParameter(info.getDefaultType(), CommonClassNames.JAVA_LANG_CLASS, 0, false)); } - myExpectedMemberName = calcExpectedMemberName(position); + myExpectedMemberName = calcExpectedMemberNameByParentCall(position); } @Nullable - private static String calcExpectedMemberName(PsiElement position) { + private static String calcExpectedMemberNameByParentCall(PsiElement position) { if (position.getParent() instanceof PsiJavaCodeReferenceElement) { PsiElement grand = position.getParent().getParent(); if (grand instanceof PsiJavaCodeReferenceElement && ((PsiJavaCodeReferenceElement)grand).getQualifier() == position.getParent()) { From e3bfaeb257fcf9cde859a50f075ddc7152926d27 Mon Sep 17 00:00:00 2001 From: Sergey Savenko Date: Thu, 5 Nov 2015 15:36:34 +0300 Subject: [PATCH 05/16] DBE-1754: associate versions with plugin id regardless of whether a plugin is bundled ResourceVersions maps plugin ids to their versions. For bundled plugins, core plugin id was used. Core plugin class loader doesn't have bundled plugin resources on it's classpath, when running on production jars. This led to a version being updated on attempt to run startup scripts, while no resources were extracted. Further checks on whether resources should be extracted were failing. --- .../com/intellij/ide/extensionResources/ResourceVersions.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/ide/extensionResources/ResourceVersions.java b/platform/lang-impl/src/com/intellij/ide/extensionResources/ResourceVersions.java index 098c65746b04..af3f1b6d99cb 100644 --- a/platform/lang-impl/src/com/intellij/ide/extensionResources/ResourceVersions.java +++ b/platform/lang-impl/src/com/intellij/ide/extensionResources/ResourceVersions.java @@ -100,8 +100,10 @@ class ResourceVersions implements PersistentStateComponent Date: Thu, 5 Nov 2015 15:36:47 +0300 Subject: [PATCH 06/16] older projects compatibility: read build process heap size from workspace.xml as a fallback value (IDEA-147362) --- .../src/com/intellij/compiler/CompilerConfigurationImpl.java | 5 +++++ .../intellij/compiler/CompilerWorkspaceConfiguration.java | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java b/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java index 9f701721e4f0..05c27526775a 100644 --- a/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java +++ b/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java @@ -685,6 +685,11 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements break; } } + if (myState.BUILD_PROCESS_HEAP_SIZE == DEFAULT_BUILD_PROCESS_HEAP_SIZE) { + final CompilerWorkspaceConfiguration workspace = CompilerWorkspaceConfiguration.getInstance(myProject); + // older version compatibility: as a fallback load this setting from workspace + myState.BUILD_PROCESS_HEAP_SIZE = workspace.COMPILER_PROCESS_HEAP_SIZE; + } } final Element notNullAssertions = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.ADD_NOTNULL_ASSERTIONS); diff --git a/java/compiler/openapi/src/com/intellij/compiler/CompilerWorkspaceConfiguration.java b/java/compiler/openapi/src/com/intellij/compiler/CompilerWorkspaceConfiguration.java index 74ad7cfae9b1..27831b7043b2 100644 --- a/java/compiler/openapi/src/com/intellij/compiler/CompilerWorkspaceConfiguration.java +++ b/java/compiler/openapi/src/com/intellij/compiler/CompilerWorkspaceConfiguration.java @@ -45,6 +45,11 @@ public class CompilerWorkspaceConfiguration implements PersistentStateComponent< public boolean CLEAR_OUTPUT_DIRECTORY = true; public boolean MAKE_PROJECT_ON_SAVE = false; // until we fix problems with several open projects (IDEA-104064), daemon slowness (IDEA-104666) public boolean PARALLEL_COMPILATION = false; + /** + * @Deprecated. Use corresponding value from CompilerConfiguration + * This field is left here for compatibility with older projects + */ + public int COMPILER_PROCESS_HEAP_SIZE = 700; public String COMPILER_PROCESS_ADDITIONAL_VM_OPTIONS = ""; public boolean REBUILD_ON_DEPENDENCY_CHANGE = true; From 29fc81a6967af67222ee8a5e2cae4a8d15bcf829 Mon Sep 17 00:00:00 2001 From: Sergey Ignatov Date: Thu, 5 Nov 2015 16:01:53 +0300 Subject: [PATCH 07/16] devkit: don't hold psi in quick fixed and cleanup --- .../devkit/src/actions/NewActionDialog.java | 25 ++++---- .../ComponentNotRegisteredInspection.java | 37 ++++++------ .../quickfix/AbstractRegisterFix.java | 30 ++++++---- .../src/inspections/quickfix/BaseFix.java | 37 ++++++------ .../quickfix/CreateConstructorFix.java | 23 ++++---- .../quickfix/ImplementOrExtendFix.java | 58 +++++++++++-------- .../quickfix/RegisterActionFix.java | 14 +++-- .../quickfix/RegisterComponentFix.java | 8 ++- plugins/devkit/src/util/PsiUtil.java | 23 +++++--- 9 files changed, 138 insertions(+), 117 deletions(-) diff --git a/plugins/devkit/src/actions/NewActionDialog.java b/plugins/devkit/src/actions/NewActionDialog.java index 779929ceb818..d3a155f7dbdd 100644 --- a/plugins/devkit/src/actions/NewActionDialog.java +++ b/plugins/devkit/src/actions/NewActionDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -24,7 +24,6 @@ import com.intellij.openapi.keymap.KeymapUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.TextFieldWithBrowseButton; -import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiNameHelper; import com.intellij.ui.ColoredListCellRenderer; @@ -78,7 +77,7 @@ public class NewActionDialog extends DialogWrapper implements ActionData { private Project myProject; private ButtonGroup myAnchorButtonGroup; - public NewActionDialog(PsiClass actionClass) { + public NewActionDialog(@NotNull PsiClass actionClass) { this(actionClass.getProject()); myActionNameEdit.setText(actionClass.getQualifiedName()); @@ -89,18 +88,18 @@ public class NewActionDialog extends DialogWrapper implements ActionData { } } - protected NewActionDialog(final Project project) { + protected NewActionDialog(Project project) { super(project, false); myProject = project; init(); setTitle(DevKitBundle.message("new.action.dialog.title")); final ActionManager actionManager = ActionManager.getInstance(); - final String[] actionIds = actionManager.getActionIds(""); + String[] actionIds = actionManager.getActionIds(""); Arrays.sort(actionIds); - final List actionGroups = new ArrayList(); + List actionGroups = new ArrayList(); for(String actionId: actionIds) { if (actionManager.isGroup(actionId)) { - final AnAction anAction = actionManager.getAction(actionId); + AnAction anAction = actionManager.getAction(actionId); if (anAction instanceof DefaultActionGroup) { actionGroups.add((ActionGroup) anAction); } @@ -115,7 +114,7 @@ public class NewActionDialog extends DialogWrapper implements ActionData { myActionList.setListData(ArrayUtil.EMPTY_OBJECT_ARRAY); } else { - final AnAction[] actions = group.getChildren(null); + AnAction[] actions = group.getChildren(null); // filter out actions that don't have IDs - they can't be used for anchoring in plugin.xml List realActions = new ArrayList(); for(AnAction action: actions) { @@ -128,7 +127,7 @@ public class NewActionDialog extends DialogWrapper implements ActionData { } }); new ListSpeedSearch(myGroupList, new Function() { - public String fun(final Object o) { + public String fun(Object o) { return ActionManager.getInstance().getId((AnAction) o); } }); @@ -140,7 +139,7 @@ public class NewActionDialog extends DialogWrapper implements ActionData { } }); - final MyDocumentListener listener = new MyDocumentListener(); + MyDocumentListener listener = new MyDocumentListener(); myActionIdEdit.getDocument().addDocumentListener(listener); myActionNameEdit.getDocument().addDocumentListener(listener); myActionTextEdit.getDocument().addDocumentListener(listener); @@ -158,8 +157,8 @@ public class NewActionDialog extends DialogWrapper implements ActionData { myFirstKeystrokeEdit.getDocument().addDocumentListener(listener); myClearFirstKeystroke.setText(null); - final Icon icon = AllIcons.Actions.Cancel; - final Dimension size = new Dimension(icon.getIconWidth(), icon.getIconHeight()); + Icon icon = AllIcons.Actions.Cancel; + Dimension size = new Dimension(icon.getIconWidth(), icon.getIconHeight()); myClearFirstKeystroke.setIcon(icon); myClearFirstKeystroke.setPreferredSize(size); myClearFirstKeystroke.setMaximumSize(size); @@ -266,7 +265,7 @@ public class NewActionDialog extends DialogWrapper implements ActionData { protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) { AnAction group = (AnAction) value; append(ActionManager.getInstance().getId(group), SimpleTextAttributes.REGULAR_ATTRIBUTES); - final String text = group.getTemplatePresentation().getText(); + String text = group.getTemplatePresentation().getText(); if (text != null) { append(" (" + text + ")", SimpleTextAttributes.REGULAR_ATTRIBUTES); } diff --git a/plugins/devkit/src/inspections/ComponentNotRegisteredInspection.java b/plugins/devkit/src/inspections/ComponentNotRegisteredInspection.java index efa00629281f..63a6de641a04 100644 --- a/plugins/devkit/src/inspections/ComponentNotRegisteredInspection.java +++ b/plugins/devkit/src/inspections/ComponentNotRegisteredInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -40,9 +40,6 @@ import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -/** - * @author swr - */ public class ComponentNotRegisteredInspection extends DevKitInspectionBase { public boolean CHECK_ACTIONS = true; public boolean IGNORE_NON_PUBLIC = true; @@ -65,7 +62,7 @@ public class ComponentNotRegisteredInspection extends DevKitInspectionBase { @Nullable public JComponent createOptionsPanel() { - final JPanel jPanel = new JPanel(); + JPanel jPanel = new JPanel(); jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS)); final JCheckBox ignoreNonPublic = new JCheckBox( @@ -82,7 +79,7 @@ public class ComponentNotRegisteredInspection extends DevKitInspectionBase { CHECK_ACTIONS); checkJavaActions.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { - final boolean selected = checkJavaActions.isSelected(); + boolean selected = checkJavaActions.isSelected(); CHECK_ACTIONS = selected; ignoreNonPublic.setEnabled(selected); } @@ -95,8 +92,8 @@ public class ComponentNotRegisteredInspection extends DevKitInspectionBase { @Nullable public ProblemDescriptor[] checkClass(@NotNull PsiClass checkedClass, @NotNull InspectionManager manager, boolean isOnTheFly) { - final PsiFile psiFile = checkedClass.getContainingFile(); - final PsiIdentifier classIdentifier = checkedClass.getNameIdentifier(); + PsiFile psiFile = checkedClass.getContainingFile(); + PsiIdentifier classIdentifier = checkedClass.getNameIdentifier(); if (checkedClass.getQualifiedName() != null && classIdentifier != null && psiFile != null && @@ -108,11 +105,11 @@ public class ComponentNotRegisteredInspection extends DevKitInspectionBase { return null; } - final PsiManager psiManager = checkedClass.getManager(); - final GlobalSearchScope scope = checkedClass.getResolveScope(); + PsiManager psiManager = checkedClass.getManager(); + GlobalSearchScope scope = checkedClass.getResolveScope(); if (CHECK_ACTIONS) { - final PsiClass actionClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(AnAction.class.getName(), scope); + PsiClass actionClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(AnAction.class.getName(), scope); if (actionClass == null) { // stop if action class cannot be found (non-devkit module/project) return null; @@ -122,8 +119,8 @@ public class ComponentNotRegisteredInspection extends DevKitInspectionBase { return null; } if (!isActionRegistered(checkedClass) && canFix(checkedClass)) { - final LocalQuickFix fix = new RegisterActionFix(checkedClass); - final ProblemDescriptor problem = manager.createProblemDescriptor( + LocalQuickFix fix = new RegisterActionFix(org.jetbrains.idea.devkit.util.PsiUtil.createPointer(checkedClass)); + ProblemDescriptor problem = manager.createProblemDescriptor( classIdentifier, DevKitBundle.message("inspections.component.not.registered.message", DevKitBundle.message("new.menu.action.text")), @@ -136,17 +133,17 @@ public class ComponentNotRegisteredInspection extends DevKitInspectionBase { } } - final ComponentType[] types = ComponentType.values(); + ComponentType[] types = ComponentType.values(); for (ComponentType type : types) { - final PsiClass compClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(type.myClassName, scope); + PsiClass compClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(type.myClassName, scope); if (compClass == null) { // stop if component classes cannot be found (non-devkit module/project) return null; } if (checkedClass.isInheritor(compClass, true)) { if (getRegistrationTypes(checkedClass, false) == null && canFix(checkedClass)) { - final LocalQuickFix fix = new RegisterComponentFix(type, checkedClass); - final ProblemDescriptor problem = manager.createProblemDescriptor(classIdentifier, + LocalQuickFix fix = new RegisterComponentFix(type, org.jetbrains.idea.devkit.util.PsiUtil.createPointer(checkedClass)); + ProblemDescriptor problem = manager.createProblemDescriptor(classIdentifier, DevKitBundle.message("inspections.component.not.registered.message", DevKitBundle.message(type.myPropertyKey)), fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly); @@ -162,10 +159,10 @@ public class ComponentNotRegisteredInspection extends DevKitInspectionBase { } private static boolean canFix(PsiClass psiClass) { - final Project project = psiClass.getProject(); - final PsiFile psiFile = psiClass.getContainingFile(); + Project project = psiClass.getProject(); + PsiFile psiFile = psiClass.getContainingFile(); LOG.assertTrue(psiFile != null); - final Module module = ModuleUtilCore.findModuleForFile(psiFile.getVirtualFile(), project); + Module module = ModuleUtilCore.findModuleForFile(psiFile.getVirtualFile(), project); return PluginModuleType.isPluginModuleOrDependency(module); } } diff --git a/plugins/devkit/src/inspections/quickfix/AbstractRegisterFix.java b/plugins/devkit/src/inspections/quickfix/AbstractRegisterFix.java index 0fe0e82ae95b..294332acec5d 100644 --- a/plugins/devkit/src/inspections/quickfix/AbstractRegisterFix.java +++ b/plugins/devkit/src/inspections/quickfix/AbstractRegisterFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -26,6 +26,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiFile; +import com.intellij.psi.SmartPsiElementPointer; import com.intellij.psi.xml.XmlFile; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NonNls; @@ -38,11 +39,11 @@ import org.jetbrains.idea.devkit.util.DescriptorUtil; import java.util.List; abstract class AbstractRegisterFix implements LocalQuickFix, DescriptorUtil.Patcher { - protected final PsiClass myClass; - private static final Logger LOG = Logger.getInstance("org.jetbrains.idea.devkit.inspections.quickfix.AbstractRegisterFix"); + protected final SmartPsiElementPointer myPointer; + protected static final Logger LOG = Logger.getInstance(AbstractRegisterFix.class); - public AbstractRegisterFix(PsiClass klass) { - myClass = klass; + public AbstractRegisterFix(@NotNull SmartPsiElementPointer klass) { + myPointer = klass; } @NotNull @@ -60,7 +61,7 @@ abstract class AbstractRegisterFix implements LocalQuickFix, DescriptorUtil.Patc // copy of com.intellij.ide.actions.CreateElementActionBase.filterMessage() protected static String filterMessage(String message) { if (message == null) return null; - @NonNls final String ioExceptionPrefix = "java.io.IOException:"; + @NonNls String ioExceptionPrefix = "java.io.IOException:"; if (message.startsWith(ioExceptionPrefix)) { message = message.substring(ioExceptionPrefix.length()); } @@ -69,7 +70,12 @@ abstract class AbstractRegisterFix implements LocalQuickFix, DescriptorUtil.Patc public void applyFix(@NotNull final Project project, @NotNull ProblemDescriptor descriptor) { if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.getPsiElement())) return; - final PsiFile psiFile = myClass.getContainingFile(); + PsiFile psiFile = myPointer.getContainingFile(); + final PsiClass element = myPointer.getElement(); + if (element == null) { + LOG.info("Element is null for PsiPointer: " + myPointer); + return; + } LOG.assertTrue(psiFile != null); final Module module = ModuleUtil.findModuleForFile(psiFile.getVirtualFile(), project); assert module != null; @@ -78,26 +84,26 @@ abstract class AbstractRegisterFix implements LocalQuickFix, DescriptorUtil.Patc public void run() { try { if (PluginModuleType.isOfType(module)) { - final XmlFile pluginXml = PluginModuleType.getPluginXml(module); + XmlFile pluginXml = PluginModuleType.getPluginXml(module); if (pluginXml != null) { - DescriptorUtil.patchPluginXml(AbstractRegisterFix.this, myClass, pluginXml); + DescriptorUtil.patchPluginXml(AbstractRegisterFix.this, element, pluginXml); } } else { List modules = PluginModuleType.getCandidateModules(module); if (modules.size() > 1) { - final ChooseModulesDialog dialog = new ChooseModulesDialog(project, modules, getName()); + ChooseModulesDialog dialog = new ChooseModulesDialog(project, modules, getName()); if (!dialog.showAndGet()) { return; } modules = dialog.getSelectedModules(); } - final XmlFile[] pluginXmls = new XmlFile[modules.size()]; + XmlFile[] pluginXmls = new XmlFile[modules.size()]; for (int i = 0; i < pluginXmls.length; i++) { pluginXmls[i] = PluginModuleType.getPluginXml(modules.get(i)); } - DescriptorUtil.patchPluginXml(AbstractRegisterFix.this, myClass, pluginXmls); + DescriptorUtil.patchPluginXml(AbstractRegisterFix.this, element, pluginXmls); } CommandProcessor.getInstance().markCurrentCommandAsGlobal(project); } diff --git a/plugins/devkit/src/inspections/quickfix/BaseFix.java b/plugins/devkit/src/inspections/quickfix/BaseFix.java index 6dd775740ca5..fdc1b4d9b5b5 100644 --- a/plugins/devkit/src/inspections/quickfix/BaseFix.java +++ b/plugins/devkit/src/inspections/quickfix/BaseFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -24,43 +24,42 @@ import com.intellij.openapi.vfs.ReadonlyStatusHandler; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; +import com.intellij.psi.SmartPsiElementPointer; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; -import org.jetbrains.idea.devkit.DevKitBundle; import org.jetbrains.annotations.NotNull; +import org.jetbrains.idea.devkit.DevKitBundle; -/** - * @author swr - */ abstract class BaseFix implements LocalQuickFix { - protected final PsiElement myElement; + protected final SmartPsiElementPointer myPointer; protected final boolean myOnTheFly; - protected BaseFix(PsiElement element, boolean onTheFly) { - myElement = element; + protected BaseFix(@NotNull SmartPsiElementPointer pointer, boolean onTheFly) { + myPointer = pointer; myOnTheFly = onTheFly; } public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { // can happen during batch-inspection if resolution has already been applied // to plugin.xml or java class - if (!myElement.isValid()) return; + PsiElement element = myPointer.getElement(); + if (element == null || !element.isValid()) return; - final boolean external = descriptor.getPsiElement().getContainingFile() != myElement.getContainingFile(); + boolean external = descriptor.getPsiElement().getContainingFile() != element.getContainingFile(); if (external) { - final PsiClass clazz = PsiTreeUtil.getParentOfType(myElement, PsiClass.class, false); - final ReadonlyStatusHandler readonlyStatusHandler = ReadonlyStatusHandler.getInstance(project); - final VirtualFile[] files = new VirtualFile[]{myElement.getContainingFile().getVirtualFile()}; - final ReadonlyStatusHandler.OperationStatus status = readonlyStatusHandler.ensureFilesWritable(files); + PsiClass clazz = PsiTreeUtil.getParentOfType(element, PsiClass.class, false); + ReadonlyStatusHandler readonlyStatusHandler = ReadonlyStatusHandler.getInstance(project); + VirtualFile[] files = new VirtualFile[]{element.getContainingFile().getVirtualFile()}; + ReadonlyStatusHandler.OperationStatus status = readonlyStatusHandler.ensureFilesWritable(files); if (status.hasReadonlyFiles()) { - final String className = clazz != null ? clazz.getQualifiedName() : myElement.getContainingFile().getName(); + String className = clazz != null ? clazz.getQualifiedName() : element.getContainingFile().getName(); Messages.showMessageDialog(project, - DevKitBundle.message("inspections.registration.problems.quickfix.read-only", - className), - getName(), - Messages.getErrorIcon()); + DevKitBundle.message("inspections.registration.problems.quickfix.read-only", + className), + getName(), + Messages.getErrorIcon()); return; } } diff --git a/plugins/devkit/src/inspections/quickfix/CreateConstructorFix.java b/plugins/devkit/src/inspections/quickfix/CreateConstructorFix.java index cce73cd8d504..d0d53902c30f 100644 --- a/plugins/devkit/src/inspections/quickfix/CreateConstructorFix.java +++ b/plugins/devkit/src/inspections/quickfix/CreateConstructorFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -17,22 +17,17 @@ package org.jetbrains.idea.devkit.inspections.quickfix; import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.openapi.project.Project; -import com.intellij.psi.JavaPsiFacade; -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiMethod; -import com.intellij.psi.PsiModifier; +import com.intellij.psi.*; import com.intellij.psi.util.PsiUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.idea.devkit.DevKitBundle; -/** - * @author swr - */ -public class CreateConstructorFix extends BaseFix { +import static org.jetbrains.idea.devkit.util.PsiUtil.createPointer; - public CreateConstructorFix(PsiClass checkedClass, boolean onTheFly) { - super(checkedClass, onTheFly); +public class CreateConstructorFix extends BaseFix { + public CreateConstructorFix(@NotNull PsiClass aClass, boolean isOnTheFly) { + super(createPointer(aClass), isOnTheFly); } @NotNull @@ -46,12 +41,14 @@ public class CreateConstructorFix extends BaseFix { } protected void doFix(Project project, ProblemDescriptor descriptor, boolean external) throws IncorrectOperationException { - final PsiClass clazz = (PsiClass)myElement; + PsiElement element = myPointer.getElement(); + if (!(element instanceof PsiClass)) return; + PsiClass clazz = (PsiClass)element; PsiMethod ctor = JavaPsiFacade.getInstance(clazz.getProject()).getElementFactory().createConstructor(); PsiUtil.setModifierProperty(ctor, PsiModifier.PUBLIC, true); - final PsiMethod[] constructors = clazz.getConstructors(); + PsiMethod[] constructors = clazz.getConstructors(); if (constructors.length > 0) { ctor = (PsiMethod)clazz.addBefore(ctor, constructors[0]); } else { diff --git a/plugins/devkit/src/inspections/quickfix/ImplementOrExtendFix.java b/plugins/devkit/src/inspections/quickfix/ImplementOrExtendFix.java index 31693193819e..1acf58c51320 100644 --- a/plugins/devkit/src/inspections/quickfix/ImplementOrExtendFix.java +++ b/plugins/devkit/src/inspections/quickfix/ImplementOrExtendFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -25,32 +25,35 @@ import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.idea.devkit.DevKitBundle; -/** - * @author swr - */ +import static org.jetbrains.idea.devkit.util.PsiUtil.createPointer; + public class ImplementOrExtendFix extends BaseFix { + private final SmartPsiElementPointer myCompClassPointer; - private final PsiClass myCompClass; - - private ImplementOrExtendFix(PsiClass compClass, PsiClass checkedClass, boolean onTheFly) { - super(checkedClass, onTheFly); - myCompClass = compClass; + private ImplementOrExtendFix(@NotNull PsiClass compClass, + @NotNull PsiClass checkedClass, + boolean onTheFly) { + super(createPointer(checkedClass), onTheFly); + myCompClassPointer = createPointer(compClass); } + @NotNull public static LocalQuickFix[] createFix(PsiClass compClass, PsiClass checkedClass, boolean onTheFly) { ImplementOrExtendFix fix = null; if (compClass.isInterface() && compClass.getImplementsList() != null) { fix = new ImplementOrExtendFix(compClass, checkedClass, onTheFly); - } else if (!compClass.isInterface()) { - final PsiReferenceList extendsList = checkedClass.getExtendsList(); + } + else if (!compClass.isInterface()) { + PsiReferenceList extendsList = checkedClass.getExtendsList(); if (extendsList != null) { if (extendsList.getReferenceElements().length == 0) { fix = new ImplementOrExtendFix(compClass, checkedClass, onTheFly); - } else if (extendsList.getReferenceElements().length == 1) { + } + else if (extendsList.getReferenceElements().length == 1) { // check for explicit "extends Object" case - final PsiClassType javaLangObject = PsiType.getJavaLangObject(checkedClass.getManager(), - checkedClass.getResolveScope()); + PsiClassType javaLangObject = PsiType.getJavaLangObject(checkedClass.getManager(), + checkedClass.getResolveScope()); if (extendsList.getReferencedTypes()[0].equals(javaLangObject)) { fix = new ImplementOrExtendFix(compClass, checkedClass, onTheFly); } @@ -62,10 +65,12 @@ public class ImplementOrExtendFix extends BaseFix { @NotNull public String getName() { - return (myCompClass.isInterface() + PsiClass clazz = myCompClassPointer.getElement(); + if (clazz == null) return "Invalid"; + return (clazz.isInterface() ? StringUtil.capitalize(DevKitBundle.message("keyword.implement")) : StringUtil.capitalize(DevKitBundle.message("keyword.extend"))) - + " '" + myCompClass.getQualifiedName() + "'"; + + " '" + clazz.getQualifiedName() + "'"; } @NotNull @@ -74,16 +79,21 @@ public class ImplementOrExtendFix extends BaseFix { } protected void doFix(Project project, ProblemDescriptor descriptor, boolean external) throws IncorrectOperationException { - final PsiClass clazz = (PsiClass)myElement; - final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(clazz.getProject()).getElementFactory(); - final PsiClassType compType = elementFactory.createType(myCompClass); + PsiElement element = myPointer.getElement(); + PsiClass compClass = myCompClassPointer.getElement(); + if (!(element instanceof PsiClass)) return; + if (compClass == null) return; + PsiClass clazz = (PsiClass)element; + PsiElementFactory elementFactory = JavaPsiFacade.getInstance(clazz.getProject()).getElementFactory(); + PsiClassType compType = elementFactory.createType(compClass); - final PsiReferenceList list; - if (myCompClass.isInterface()) { + PsiReferenceList list; + if (compClass.isInterface()) { list = clazz.getImplementsList(); assert list != null; - } else { - final PsiReferenceList extendsList = clazz.getExtendsList(); + } + else { + PsiReferenceList extendsList = clazz.getExtendsList(); assert extendsList != null; if (extendsList.getReferencedTypes().length > 0) { extendsList.getReferenceElements()[0].delete(); @@ -91,7 +101,7 @@ public class ImplementOrExtendFix extends BaseFix { list = extendsList; } - final PsiElement e = list.add(elementFactory.createReferenceElementByType(compType)); + PsiElement e = list.add(elementFactory.createReferenceElementByType(compType)); if (myOnTheFly && external && e instanceof Navigatable) ((Navigatable)e).navigate(true); } } diff --git a/plugins/devkit/src/inspections/quickfix/RegisterActionFix.java b/plugins/devkit/src/inspections/quickfix/RegisterActionFix.java index 5a56054492f9..8abdb2bce51d 100644 --- a/plugins/devkit/src/inspections/quickfix/RegisterActionFix.java +++ b/plugins/devkit/src/inspections/quickfix/RegisterActionFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -19,6 +19,7 @@ import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiClass; +import com.intellij.psi.SmartPsiElementPointer; import com.intellij.psi.xml.XmlFile; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; @@ -31,8 +32,8 @@ import org.jetbrains.idea.devkit.util.ActionType; public class RegisterActionFix extends AbstractRegisterFix { private NewActionDialog myDialog; - public RegisterActionFix(PsiClass klass) { - super(klass); + public RegisterActionFix(@NotNull SmartPsiElementPointer pointer) { + super(pointer); } protected String getType() { @@ -46,7 +47,12 @@ public class RegisterActionFix extends AbstractRegisterFix { } try { - myDialog = new NewActionDialog(myClass); + PsiClass element = myPointer.getElement(); + if (element == null) { + LOG.info("Element is null for PsiPointer: " + myPointer); + return; + } + myDialog = new NewActionDialog(element); if (myDialog.showAndGet()) { super.applyFix(project, descriptor); } diff --git a/plugins/devkit/src/inspections/quickfix/RegisterComponentFix.java b/plugins/devkit/src/inspections/quickfix/RegisterComponentFix.java index 0c3d0fd645e2..2f6c5a5b782f 100644 --- a/plugins/devkit/src/inspections/quickfix/RegisterComponentFix.java +++ b/plugins/devkit/src/inspections/quickfix/RegisterComponentFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -16,16 +16,18 @@ package org.jetbrains.idea.devkit.inspections.quickfix; import com.intellij.psi.PsiClass; +import com.intellij.psi.SmartPsiElementPointer; import com.intellij.psi.xml.XmlFile; import com.intellij.util.IncorrectOperationException; +import org.jetbrains.annotations.NotNull; import org.jetbrains.idea.devkit.DevKitBundle; import org.jetbrains.idea.devkit.util.ComponentType; public class RegisterComponentFix extends AbstractRegisterFix { private final ComponentType myType; - public RegisterComponentFix(ComponentType type, PsiClass klass) { - super(klass); + public RegisterComponentFix(ComponentType type, @NotNull SmartPsiElementPointer pointer) { + super(pointer); myType = type; } diff --git a/plugins/devkit/src/util/PsiUtil.java b/plugins/devkit/src/util/PsiUtil.java index ffa1a5b43099..99c6e86f5c34 100644 --- a/plugins/devkit/src/util/PsiUtil.java +++ b/plugins/devkit/src/util/PsiUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -39,12 +39,12 @@ public class PsiUtil { private PsiUtil() { } public static boolean isInstantiable(@NotNull PsiClass cls) { - final PsiModifierList modList = cls.getModifierList(); + PsiModifierList modList = cls.getModifierList(); if (modList == null || cls.isInterface() || modList.hasModifierProperty(PsiModifier.ABSTRACT) || !isPublicOrStaticInnerClass(cls)) { return false; } - final PsiMethod[] constructors = cls.getConstructors(); + PsiMethod[] constructors = cls.getConstructors(); if (constructors.length == 0) return true; for (PsiMethod constructor : constructors) { @@ -57,7 +57,7 @@ public class PsiUtil { } public static boolean isPublicOrStaticInnerClass(@NotNull PsiClass cls) { - final PsiModifierList modifiers = cls.getModifierList(); + PsiModifierList modifiers = cls.getModifierList(); if (modifiers == null) return false; return modifiers.hasModifierProperty(PsiModifier.PUBLIC) && @@ -66,9 +66,9 @@ public class PsiUtil { @Nullable public static String getReturnedLiteral(PsiMethod method, PsiClass cls) { - final PsiExpression value = getReturnedExpression(method); + PsiExpression value = getReturnedExpression(method); if (value instanceof PsiLiteralExpression) { - final Object str = ((PsiLiteralExpression)value).getValue(); + Object str = ((PsiLiteralExpression)value).getValue(); return str == null ? null : str.toString(); } else if (value instanceof PsiMethodCallExpression) { @@ -95,11 +95,11 @@ public class PsiUtil { if (body != null) { PsiStatement[] statements = body.getStatements(); if (statements.length == 1 && statements[0] instanceof PsiReturnStatement) { - final PsiExpression value = ((PsiReturnStatement)statements[0]).getReturnValue(); + PsiExpression value = ((PsiReturnStatement)statements[0]).getReturnValue(); if (value instanceof PsiReferenceExpression) { - final PsiElement element = ((PsiReferenceExpression)value).resolve(); + PsiElement element = ((PsiReferenceExpression)value).resolve(); if (element instanceof PsiField) { - final PsiField field = (PsiField)element; + PsiField field = (PsiField)element; if (field.hasModifierProperty(PsiModifier.FINAL)) { return field.getInitializer(); } @@ -183,4 +183,9 @@ public class PsiUtil { return true; } + + @NotNull + public static SmartPsiElementPointer createPointer(@NotNull E e) { + return SmartPointerManager.getInstance(e.getProject()).createSmartPsiElementPointer(e); + } } From 3bdbffe2fcb84a0cd1c3e83893a71d0ebbc2fee3 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Wed, 4 Nov 2015 19:55:20 +0300 Subject: [PATCH 08/16] remove unused field --- .../vcs/ui/VcsBalloonProblemNotifier.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/VcsBalloonProblemNotifier.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/VcsBalloonProblemNotifier.java index 82ff0bcc6e5a..f4fbfaebb52f 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/VcsBalloonProblemNotifier.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/VcsBalloonProblemNotifier.java @@ -41,38 +41,38 @@ public class VcsBalloonProblemNotifier implements Runnable { private final Project myProject; private final String myMessage; private final MessageType myMessageType; - private final boolean myShowOverChangesView; @Nullable private final NamedRunnable[] myNotificationListener; public VcsBalloonProblemNotifier(@NotNull final Project project, @NotNull final String message, final MessageType messageType) { - this(project, message, messageType, true, null); + this(project, message, messageType, null); } - public VcsBalloonProblemNotifier(@NotNull final Project project, @NotNull final String message, final MessageType messageType, boolean showOverChangesView, + public VcsBalloonProblemNotifier(@NotNull final Project project, + @NotNull final String message, + final MessageType messageType, @Nullable final NamedRunnable[] notificationListener) { myProject = project; myMessage = message; myMessageType = messageType; - myShowOverChangesView = showOverChangesView; myNotificationListener = notificationListener; } public static void showOverChangesView(@NotNull final Project project, @NotNull final String message, final MessageType type, final NamedRunnable... notificationListener) { - show(project, message, type, true, notificationListener); + show(project, message, type, notificationListener); } public static void showOverVersionControlView(@NotNull final Project project, @NotNull final String message, final MessageType type) { - show(project, message, type, false, null); + show(project, message, type, null); } - private static void show(final Project project, final String message, final MessageType type, final boolean showOverChangesView, + private static void show(final Project project, final String message, final MessageType type, @Nullable final NamedRunnable[] notificationListener) { final Application application = ApplicationManager.getApplication(); if (application.isHeadlessEnvironment()) return; final Runnable showErrorAction = new Runnable() { public void run() { - new VcsBalloonProblemNotifier(project, message, type, showOverChangesView, notificationListener).run(); + new VcsBalloonProblemNotifier(project, message, type, notificationListener).run(); } }; if (application.isDispatchThread()) { From da7bbf2537891f88337e7e493201eec9ea68b783 Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Thu, 5 Nov 2015 16:50:21 +0300 Subject: [PATCH 09/16] guava type migration: method parameter migration involves local variables migration if need --- .../GuavaFluentIterableConversionRule.java | 5 ++++- .../inspections/GuavaInspectionTest.java | 4 ++++ .../guava/typeMigrationRootBackTraverse.java | 17 +++++++++++++++++ .../typeMigrationRootBackTraverse_after.java | 16 ++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 java/typeMigration/testData/inspections/guava/typeMigrationRootBackTraverse.java create mode 100644 java/typeMigration/testData/inspections/guava/typeMigrationRootBackTraverse_after.java diff --git a/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaFluentIterableConversionRule.java b/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaFluentIterableConversionRule.java index 41f3b5fc97bc..c7f8ec138a9b 100644 --- a/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaFluentIterableConversionRule.java +++ b/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaFluentIterableConversionRule.java @@ -29,7 +29,6 @@ import com.intellij.refactoring.typeMigration.TypeConversionDescriptor; import com.intellij.refactoring.typeMigration.TypeConversionDescriptorBase; import com.intellij.refactoring.typeMigration.TypeMigrationLabeler; import com.intellij.refactoring.typeMigration.rules.TypeConversionRule; -import com.intellij.util.Function; import com.intellij.util.IncorrectOperationException; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; @@ -306,6 +305,10 @@ public class GuavaFluentIterableConversionRule extends BaseGuavaTypeConversionRu } break; } + else if (qualifier instanceof PsiReferenceExpression && ((PsiReferenceExpression)qualifier).resolve() instanceof PsiVariable) { + labeler.migrateExpressionType(qualifier, to, qualifier.getParent(), false, false); + break; + } else { return null; } diff --git a/java/typeMigration/test/com/intellij/codeInsight/inspections/GuavaInspectionTest.java b/java/typeMigration/test/com/intellij/codeInsight/inspections/GuavaInspectionTest.java index 285d54a50105..a12a4f578765 100644 --- a/java/typeMigration/test/com/intellij/codeInsight/inspections/GuavaInspectionTest.java +++ b/java/typeMigration/test/com/intellij/codeInsight/inspections/GuavaInspectionTest.java @@ -182,6 +182,10 @@ public class GuavaInspectionTest extends JavaCodeInsightFixtureTestCase { doTest(); } + public void testTypeMigrationRootBackTraverse() { + doTest(); + } + private void doTestNoQuickFixes(final Class... quickFixesClasses) { myFixture.configureByFile(getTestName(true) + ".java"); myFixture.enableInspections(new GuavaInspection()); diff --git a/java/typeMigration/testData/inspections/guava/typeMigrationRootBackTraverse.java b/java/typeMigration/testData/inspections/guava/typeMigrationRootBackTraverse.java new file mode 100644 index 000000000000..278051a54fbc --- /dev/null +++ b/java/typeMigration/testData/inspections/guava/typeMigrationRootBackTraverse.java @@ -0,0 +1,17 @@ +import com.google.common.collect.FluentIterable; + +import java.util.ArrayList; + +public class MainFluentIterable { + + FluentIterable m2() { + + FluentIterable it = FluentIterable.from(new ArrayList()); + + return it.transform(s -> s + s); + } + + void m3() { + System.out.println((int) m2().size()); + } +} \ No newline at end of file diff --git a/java/typeMigration/testData/inspections/guava/typeMigrationRootBackTraverse_after.java b/java/typeMigration/testData/inspections/guava/typeMigrationRootBackTraverse_after.java new file mode 100644 index 000000000000..d693a19dde25 --- /dev/null +++ b/java/typeMigration/testData/inspections/guava/typeMigrationRootBackTraverse_after.java @@ -0,0 +1,16 @@ +import java.util.ArrayList; +import java.util.stream.Stream; + +public class MainFluentIterable { + + Stream m2() { + + Stream it = new ArrayList().stream(); + + return it.map(s -> s + s); + } + + void m3() { + System.out.println((int) (int) m2().count()); + } +} \ No newline at end of file From 82d56cb1e3bc7dd7d75aa10e052d36d9b9cd2e03 Mon Sep 17 00:00:00 2001 From: Sergey Simonchik Date: Thu, 5 Nov 2015 16:53:36 +0300 Subject: [PATCH 10/16] ui: respect HiDPI displays in "Available Packages" dialog --- .../intellij/webcore/packaging/ManagePackagesDialog.form | 4 +--- .../intellij/webcore/packaging/ManagePackagesDialog.java | 8 +++++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/webcore/packaging/ManagePackagesDialog.form b/platform/lang-impl/src/com/intellij/webcore/packaging/ManagePackagesDialog.form index 9337eed33403..4f42e77828fb 100644 --- a/platform/lang-impl/src/com/intellij/webcore/packaging/ManagePackagesDialog.form +++ b/platform/lang-impl/src/com/intellij/webcore/packaging/ManagePackagesDialog.form @@ -5,9 +5,7 @@ - - - + diff --git a/platform/lang-impl/src/com/intellij/webcore/packaging/ManagePackagesDialog.java b/platform/lang-impl/src/com/intellij/webcore/packaging/ManagePackagesDialog.java index f88b4aca8392..f5be735b8aab 100644 --- a/platform/lang-impl/src/com/intellij/webcore/packaging/ManagePackagesDialog.java +++ b/platform/lang-impl/src/com/intellij/webcore/packaging/ManagePackagesDialog.java @@ -31,6 +31,7 @@ import com.intellij.ui.components.JBList; import com.intellij.util.CatchingConsumer; import com.intellij.util.Function; import com.intellij.util.ObjectUtils; +import com.intellij.util.ui.JBUI; import com.intellij.util.ui.PlatformColors; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.update.UiNotifyConnector; @@ -136,10 +137,10 @@ public class ManagePackagesDialog extends DialogWrapper { .disableRemoveAction() .addExtraAction(reloadButton) .createPanel(); - packagesPanel.setPreferredSize(new Dimension(400, -1)); - packagesPanel.setMinimumSize(new Dimension(100, -1)); + packagesPanel.setPreferredSize(new Dimension(JBUI.scale(400), -1)); + packagesPanel.setMinimumSize(new Dimension(JBUI.scale(100), -1)); myPackages.setFixedCellWidth(0); - myPackages.setFixedCellHeight(22); + myPackages.setFixedCellHeight(JBUI.scale(22)); myPackages.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); mySplitPane.setLeftComponent(packagesPanel); @@ -187,6 +188,7 @@ public class ManagePackagesDialog extends DialogWrapper { else { myInstallToUser.setVisible(false); } + myMainPanel.setPreferredSize(new Dimension(JBUI.scale(900), JBUI.scale(700))); } public void selectPackage(@NotNull InstalledPackage pkg) { From 8014a6be7f9311dc5d9c1e6d326880a38a29bfa9 Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Thu, 5 Nov 2015 16:59:41 +0300 Subject: [PATCH 11/16] guava type migration: method renamed --- .../rules/guava/GuavaFluentIterableConversionRule.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaFluentIterableConversionRule.java b/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaFluentIterableConversionRule.java index c7f8ec138a9b..f175f12b45ab 100644 --- a/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaFluentIterableConversionRule.java +++ b/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaFluentIterableConversionRule.java @@ -220,7 +220,7 @@ public class GuavaFluentIterableConversionRule extends BaseGuavaTypeConversionRu final TypeConversionDescriptor descriptor = base.create(); needSpecifyType = base.isChainedMethod(); if (needSpecifyType && !base.isFluentIterableReturnType()) { - conversionType = getTypeParametersAsText(GuavaOptionalConversionRule.JAVA_OPTIONAL, context.getType(), context); + conversionType = addTypeParameters(GuavaOptionalConversionRule.JAVA_OPTIONAL, context.getType(), context); } descriptorBase = descriptor; } @@ -228,7 +228,7 @@ public class GuavaFluentIterableConversionRule extends BaseGuavaTypeConversionRu if (descriptorBase != null) { if (needSpecifyType) { if (conversionType == null) { - conversionType = getTypeParametersAsText(StreamApiConstants.JAVA_UTIL_STREAM_STREAM, context.getType(), context); + conversionType = addTypeParameters(StreamApiConstants.JAVA_UTIL_STREAM_STREAM, context.getType(), context); } descriptorBase.withConversionType(conversionType); } @@ -238,7 +238,7 @@ public class GuavaFluentIterableConversionRule extends BaseGuavaTypeConversionRu } @NotNull - private static PsiType getTypeParametersAsText(String baseClassQualifiedName, PsiType type, PsiElement context) { + private static PsiType addTypeParameters(String baseClassQualifiedName, PsiType type, PsiElement context) { String parameterText = ""; if (type != null) { final String canonicalText = type.getCanonicalText(false); @@ -306,7 +306,7 @@ public class GuavaFluentIterableConversionRule extends BaseGuavaTypeConversionRu break; } else if (qualifier instanceof PsiReferenceExpression && ((PsiReferenceExpression)qualifier).resolve() instanceof PsiVariable) { - labeler.migrateExpressionType(qualifier, to, qualifier.getParent(), false, false); + labeler.migrateExpressionType(qualifier, addTypeParameters(StreamApiConstants.JAVA_UTIL_STREAM_STREAM, to, qualifier), qualifier.getParent(), false, false); break; } else { From 26d21de421c83295f89a466db4a6fbfab211fd69 Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Thu, 5 Nov 2015 17:10:35 +0300 Subject: [PATCH 12/16] guava type migration: testdata slightly corrected --- java/typeMigration/testData/inspections/guava/optional2.java | 1 + .../testData/inspections/guava/optional2_after.java | 1 + 2 files changed, 2 insertions(+) diff --git a/java/typeMigration/testData/inspections/guava/optional2.java b/java/typeMigration/testData/inspections/guava/optional2.java index 4fffaebceba7..c3c0922957d5 100644 --- a/java/typeMigration/testData/inspections/guava/optional2.java +++ b/java/typeMigration/testData/inspections/guava/optional2.java @@ -1,4 +1,5 @@ import com.google.common.base.Optional; +import java.util.Collections; class A { diff --git a/java/typeMigration/testData/inspections/guava/optional2_after.java b/java/typeMigration/testData/inspections/guava/optional2_after.java index 5166fb2c6ec1..4ca032234920 100644 --- a/java/typeMigration/testData/inspections/guava/optional2_after.java +++ b/java/typeMigration/testData/inspections/guava/optional2_after.java @@ -1,3 +1,4 @@ +import java.util.Collections; import java.util.Optional; class A { From d43586ad66e2d44f2470fedefed2269b8d26fcf5 Mon Sep 17 00:00:00 2001 From: Matthias Vill Date: Thu, 5 Nov 2015 10:19:55 +0100 Subject: [PATCH 13/16] Typo Changed internalization in notification title to internationalization --- .../impl/KeyboardInternationalizationNotificationManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/KeyboardInternationalizationNotificationManager.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/KeyboardInternationalizationNotificationManager.java index cc251a7be79d..bc84fde8c0b8 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/KeyboardInternationalizationNotificationManager.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/KeyboardInternationalizationNotificationManager.java @@ -60,7 +60,7 @@ public class KeyboardInternationalizationNotificationManager { KeyboardSettingsExternalizable.getDisplayLanguageNameForComponent(recentFocusedWindow) + " language." + "You can change this option in the settings of " + productName + " more..."; - String title = "Enable smart keyboard internalization for " + productName + "."; + String title = "Enable smart keyboard internationalization for " + productName + "."; return new Notification(groupDisplayId, title, text, From 86a396d8ea0585e02df3cbdda357c0cb6924f9a0 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 5 Nov 2015 11:53:41 +0100 Subject: [PATCH 14/16] test navigation: don't ever treat current class as potential test --- .../src/com/intellij/testIntegration/JavaTestFinder.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/java/java-impl/src/com/intellij/testIntegration/JavaTestFinder.java b/java/java-impl/src/com/intellij/testIntegration/JavaTestFinder.java index 6fb9c7e91c5b..3c7798a4856b 100644 --- a/java/java-impl/src/com/intellij/testIntegration/JavaTestFinder.java +++ b/java/java-impl/src/com/intellij/testIntegration/JavaTestFinder.java @@ -117,7 +117,7 @@ public class JavaTestFinder implements TestFinder { for (String eachName : names) { if (pattern.matcher(eachName).matches()) { for (PsiClass eachClass : cache.getClassesByName(eachName, scope)) { - if (isTestClass(eachClass)) { + if (isTestClass(eachClass, klass)) { if (!processor.process(Pair.create(eachClass, TestFinderHelper.calcTestNameProximity(klassName, eachName)))) { return true; } @@ -128,9 +128,9 @@ public class JavaTestFinder implements TestFinder { return false; } - protected boolean isTestClass(PsiClass eachClass) { + protected boolean isTestClass(PsiClass eachClass, PsiClass klass) { final TestFrameworks frameworks = TestFrameworks.getInstance(); - return eachClass.isPhysical() && (frameworks.isTestClass(eachClass) || frameworks.isPotentialTestClass(eachClass)); + return eachClass.isPhysical() && (frameworks.isTestClass(eachClass) || eachClass != klass && frameworks.isPotentialTestClass(eachClass)); } @Nullable From 6e853bf57108b222019b5f934c7edf155cfb9922 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 5 Nov 2015 13:36:13 +0100 Subject: [PATCH 15/16] new inference: stop at first common supertypes pair during incorporation of upper bounds (IDEA-147393) --- .../graphInference/InferenceIncorporationPhase.java | 2 +- ...irOfCommonSupertypesDuringUpUpIncorporation.java | 13 +++++++++++++ .../lambda/GraphInferenceHighlightingTest.java | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/AcceptFirstPairOfCommonSupertypesDuringUpUpIncorporation.java diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java index 1a4ad6a932fc..4f9d1f7f4837 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java @@ -301,7 +301,7 @@ public class InferenceIncorporationPhase { if (!(sType instanceof PsiWildcardType) && !(tType instanceof PsiWildcardType) && sType != null && tType != null) { addConstraint(new TypeEqualityConstraint(sType, tType)); } - return true; + return false; } }) != null; } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/AcceptFirstPairOfCommonSupertypesDuringUpUpIncorporation.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/AcceptFirstPairOfCommonSupertypesDuringUpUpIncorporation.java new file mode 100644 index 000000000000..4b7b960499b9 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/AcceptFirstPairOfCommonSupertypesDuringUpUpIncorporation.java @@ -0,0 +1,13 @@ +interface I{} +abstract class A implements I>{} +class Factory { + static > T get(Class c){ + return null; + } +} + +class Impl extends A { + static Impl get() { + return Factory.get(Impl.class); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java index 411f4cb826f0..428d3e858a87 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java @@ -311,6 +311,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase doTest(); } + public void testAcceptFirstPairOfCommonSupertypesDuringUpUpIncorporation() throws Exception { + doTest(); + } + private void doTest() throws Exception { doTest(false); } From 70c0e175904d98070efd74e04afa1ac469f979db Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 5 Nov 2015 15:19:49 +0100 Subject: [PATCH 16/16] follow IDEA-CR-6530 --- ...eneralIdBasedToSMTRunnerEventsConvertor.java | 2 +- .../GeneralToSMTRunnerEventsConvertor.java | 2 +- .../OutputToGeneralTestEventsConverter.java | 4 ++-- .../sm/runner/events/TestFinishedEvent.java | 17 +++++++++++------ .../testframework/CompositePrintable.java | 12 ++++++------ .../ui/TestsOutputConsolePrinter.java | 2 +- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralIdBasedToSMTRunnerEventsConvertor.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralIdBasedToSMTRunnerEventsConvertor.java index be740b238b62..ad1c07c0fe76 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralIdBasedToSMTRunnerEventsConvertor.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralIdBasedToSMTRunnerEventsConvertor.java @@ -193,7 +193,7 @@ public class GeneralIdBasedToSMTRunnerEventsConvertor extends GeneralTestEventsP if (node != null) { SMTestProxy testProxy = node.getProxy(); testProxy.setDuration(testFinishedEvent.getDuration()); - testProxy.setInputFilePath(testFinishedEvent.getOutputFile()); + testProxy.setFrameworkOutputFile(testFinishedEvent.getOutputFile()); testProxy.setFinished(); fireOnTestFinished(testProxy); terminateNode(node, State.FINISHED); diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java index 6ea423374474..7a5df90caf34 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java @@ -312,7 +312,7 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso } testProxy.setDuration(duration); - testProxy.setInputFilePath(testFinishedEvent.getOutputFile()); + testProxy.setFrameworkOutputFile(testFinishedEvent.getOutputFile()); testProxy.setFinished(); myRunningTestsFullNameToProxy.remove(fullTestName); myCurrentChildren.remove(testProxy); diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/OutputToGeneralTestEventsConverter.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/OutputToGeneralTestEventsConverter.java index 2a7adbebb7f1..0d4ecbbf61ab 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/OutputToGeneralTestEventsConverter.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/OutputToGeneralTestEventsConverter.java @@ -410,8 +410,8 @@ public class OutputToGeneralTestEventsConverter implements ProcessOutputConsumer duration = convertToLong(durationStr, testFinished); } - TestFinishedEvent testFinishedEvent = new TestFinishedEvent(testFinished, duration); - testFinishedEvent.setOutputFile(testFinished.getAttributes().get(ATTR_KEY_TEST_OUTPUT_FILE)); + TestFinishedEvent testFinishedEvent = new TestFinishedEvent(testFinished, duration, + testFinished.getAttributes().get(ATTR_KEY_TEST_OUTPUT_FILE)); fireOnTestFinished(testFinishedEvent); } diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/TestFinishedEvent.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/TestFinishedEvent.java index e82b8d074061..5f520792da2a 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/TestFinishedEvent.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/events/TestFinishedEvent.java @@ -22,15 +22,24 @@ import org.jetbrains.annotations.Nullable; public class TestFinishedEvent extends TreeNodeEvent { private final long myDuration; - private String myOutputFile; + private final String myOutputFile; public TestFinishedEvent(@NotNull TestFinished testFinished, long duration) { - this(testFinished.getTestName(), TreeNodeEvent.getNodeId(testFinished), duration); + this(testFinished, duration, null); + } + + public TestFinishedEvent(@NotNull TestFinished testFinished, long duration, String outputFile) { + this(testFinished.getTestName(), TreeNodeEvent.getNodeId(testFinished), duration, outputFile); } public TestFinishedEvent(@Nullable String name, int id, long duration) { + this(name, id, duration, null); + } + + public TestFinishedEvent(@Nullable String name, int id, long duration, String outputFile) { super(name, id); myDuration = duration; + myOutputFile = outputFile; } public TestFinishedEvent(@NotNull String name, long duration) { @@ -52,10 +61,6 @@ public class TestFinishedEvent extends TreeNodeEvent { append(buf, "duration", myDuration); } - public void setOutputFile(String outputFile) { - myOutputFile = outputFile; - } - public String getOutputFile() { return myOutputFile; } diff --git a/platform/testRunner/src/com/intellij/execution/testframework/CompositePrintable.java b/platform/testRunner/src/com/intellij/execution/testframework/CompositePrintable.java index a03f89d03c75..8fef9564b9bf 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/CompositePrintable.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/CompositePrintable.java @@ -40,7 +40,7 @@ public class CompositePrintable implements Printable, Disposable { protected int myExceptionMark; private int myCurrentSize = 0; private String myOutputFile = null; - private String myInputFile; + private String myFrameworkOutputFile; private static final Alarm myAlarm = new Alarm(Alarm.ThreadToUse.SHARED_THREAD); public void flush() { @@ -135,15 +135,15 @@ public class CompositePrintable implements Printable, Disposable { myOutputFile = outputFile; } - public void setInputFilePath(String inputFilePath) { - myInputFile = inputFilePath; + public void setFrameworkOutputFile(String frameworkOutputFile) { + myFrameworkOutputFile = frameworkOutputFile; } - public void printFromInputFile(final Printer console) { - if (myInputFile != null) { + public void printFromFrameworkOutputFile(final Printer console) { + if (myFrameworkOutputFile != null) { final Runnable runnable = new Runnable() { public void run() { - final File inputFile = new File(myInputFile); + final File inputFile = new File(myFrameworkOutputFile); if (inputFile.exists()) { try { final String fileText = FileUtil.loadFile(inputFile); diff --git a/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsOutputConsolePrinter.java b/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsOutputConsolePrinter.java index 2134c6d20918..4f5b0cb2e3a9 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsOutputConsolePrinter.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/ui/TestsOutputConsolePrinter.java @@ -110,7 +110,7 @@ public class TestsOutputConsolePrinter implements Printer, Disposable { final AbstractTestProxy currentProxyOrRoot = getCurrentProxyOrRoot(); CompositePrintable.invokeInAlarm(clearRunnable); currentProxyOrRoot.printOn(this); - currentProxyOrRoot.printFromInputFile(this); + currentProxyOrRoot.printFromFrameworkOutputFile(this); CompositePrintable.invokeInAlarm(scrollRunnable); }