Merge remote-tracking branch 'origin/master' into mark_folder_as
authorAnton Makeev <Anton.Makeev@jetbrains.com>
Fri, 13 Nov 2015 16:17:33 +0000 (17:17 +0100)
committerAnton Makeev <Anton.Makeev@jetbrains.com>
Fri, 13 Nov 2015 16:17:33 +0000 (17:17 +0100)
358 files changed:
.idea/compiler.xml
build/conf/classVersions.txt
build/lib/jps/antlayout.jar
build/lib/jps/groovy-jps-plugin.jar
build/lib/jps/groovy-rt-constants.jar [new file with mode: 0644]
build/lib/jps/groovy_rt.jar
build/lib/jps/jps-builders.jar
build/lib/jps/jps-model.jar
build/lib/jps/ui-designer-jps-plugin.jar
build/lib/jps/util.jar
community-resources/community-resources.iml
java/execution/impl/src/com/intellij/execution/testDiscovery/TestDiscoveryConfigurable.java
java/idea-ui/src/com/intellij/platform/templates/SaveProjectAsTemplateAction.java
java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java
java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java
java/java-analysis-impl/src/com/intellij/codeInsight/guess/impl/ExpressionTypeMemoryState.java
java/java-analysis-impl/src/com/intellij/codeInsight/guess/impl/GuessManagerImpl.java
java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractChecker.java
java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowRunner.java
java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryState.java
java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java
java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaPsiUtil.java
java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaUtil.java
java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaVariableState.java
java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/StateMerger.java
java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ValuableDataFlowRunner.java
java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaTypeValue.java
java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaValueFactory.java
java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaVariableValue.java
java/java-analysis-impl/src/com/intellij/codeInspection/uncheckedWarnings/UncheckedWarningLocalInspectionBase.java
java/java-analysis-impl/src/com/intellij/codeInspection/unnecessaryModuleDependency/UnnecessaryModuleDependencyInspection.java
java/java-impl/src/com/intellij/codeInsight/JavaTargetElementEvaluator.java
java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddVariableInitializerFix.java
java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/StaticImportMethodFix.java
java/java-impl/src/com/intellij/refactoring/rename/RenameJavaVariableProcessor.java
java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationProcessor.java
java/java-impl/src/com/intellij/refactoring/typeMigration/TypeMigrationStatementProcessor.java
java/java-impl/src/com/intellij/refactoring/typeMigration/rules/RootTypeConversionRule.java
java/java-impl/src/com/intellij/usages/impl/rules/JavaUsageTypeProvider.java
java/java-indexing-impl/src/com/intellij/psi/impl/search/JavaFunctionalExpressionSearcher.java
java/java-psi-api/src/com/intellij/psi/PsiIntersectionType.java
java/java-psi-api/src/com/intellij/psi/util/TypesDistinctProver.java
java/java-psi-impl/java-psi-impl.iml
java/java-psi-impl/src/com/intellij/psi/impl/source/ClassInnerStuffCache.java
java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/FunctionalInterfaceParameterizationUtil.java
java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java
java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiReferenceExpressionImpl.java
java/java-psi-impl/src/messages/JavaErrorMessages.properties
java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ProvablyDistinctForWildcardsWithArrayBounds.java [new file with mode: 0644]
java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/UncheckedWarningsWhenInferredTypeLeadsToRawRoGenericAssignment.java [new file with mode: 0644]
java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/findUsages/ClassFromJdkMethodRef.java [new file with mode: 0644]
java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/EliminateIntersectionTypeWildcardElimination.java [new file with mode: 0644]
java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/IncorporationOfBoundsAsTypeArguments.java [new file with mode: 0644]
java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/IncorporationWithRawSubstitutors.java [new file with mode: 0644]
java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/RawInferredTypeCheck.java [new file with mode: 0644]
java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/wildcardParametrization/NonWildcardParametrization.java
java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/staticImportMethod/afterOverloads.java [new file with mode: 0644]
java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/staticImportMethod/beforeOverloads.java [new file with mode: 0644]
java/java-tests/testData/codeInsight/slice/backward/TryCatchFinally.java [new file with mode: 0644]
java/java-tests/testData/refactoring/renameField/afterOverridingSetterParameterRenamed.java [new file with mode: 0644]
java/java-tests/testData/refactoring/renameField/beforeOverridingSetterParameterRenamed.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/codeInsight/completion/SeemsScrambledTest.groovy [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java
java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/FindFunctionalInterfaceTest.java
java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GenericsHighlighting8Test.java
java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java
java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java
java/java-tests/testSrc/com/intellij/find/FindManagerTest.java
java/java-tests/testSrc/com/intellij/navigation/ShowImplementationHandlerTest.java
java/java-tests/testSrc/com/intellij/project/LoadProjectTest.java
java/java-tests/testSrc/com/intellij/psi/AstLeaksTest.groovy
java/java-tests/testSrc/com/intellij/psi/PsiConcurrencyStressTest.java
java/java-tests/testSrc/com/intellij/psi/impl/file/impl/PsiEventsTest.java
java/java-tests/testSrc/com/intellij/refactoring/RenameFieldTest.java
java/java-tests/testSrc/com/intellij/slicer/SliceBackwardTest.java
java/typeMigration/src/com/intellij/refactoring/typeMigration/TypeMigrationVariableTypeFixProvider.java
java/typeMigration/src/com/intellij/refactoring/typeMigration/inspections/GuavaInspection.java
java/typeMigration/src/com/intellij/refactoring/typeMigration/intentions/ConvertAtomicToLongAdderIntention.java
java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/BaseGuavaTypeConversionRule.java
java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaConversionUtil.java [new file with mode: 0644]
java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaFluentIterableConversionRule.java
java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaFunctionConversionRule.java
java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaOptionalConversionRule.java
java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaOptionalConversionUtil.java [new file with mode: 0644]
java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaPredicateConversionRule.java
java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaSupplierConversionRule.java
java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/LambdaParametersTypeConversionDescriptor.java
java/typeMigration/test/com/intellij/codeInsight/inspections/GuavaInspectionTest.java
java/typeMigration/test/com/intellij/refactoring/TypeMigrationTest.java
java/typeMigration/testData/inspections/guava/fluentIterableChainSeparatedByMethods_after.java
java/typeMigration/testData/inspections/guava/fluentIterableWithStaticallyImportedFrom_after.java
java/typeMigration/testData/inspections/guava/migrateArrays.java [new file with mode: 0644]
java/typeMigration/testData/inspections/guava/migrateArrays_after.java [new file with mode: 0644]
java/typeMigration/testData/inspections/guava/optional2_after.java
java/typeMigration/testData/inspections/guava/optionalTransform.java [new file with mode: 0644]
java/typeMigration/testData/inspections/guava/optionalTransform2.java [new file with mode: 0644]
java/typeMigration/testData/inspections/guava/optionalTransform2_after.java [new file with mode: 0644]
java/typeMigration/testData/inspections/guava/optionalTransform_after.java [new file with mode: 0644]
java/typeMigration/testData/inspections/guava/removeMethodReference.java [new file with mode: 0644]
java/typeMigration/testData/inspections/guava/removeMethodReference_after.java [new file with mode: 0644]
java/typeMigration/testData/inspections/guava/returnType_after.java
java/typeMigration/testData/inspections/guava/simplifyOptionalComposition.java [new file with mode: 0644]
java/typeMigration/testData/inspections/guava/simplifyOptionalComposition_after.java [new file with mode: 0644]
java/typeMigration/testData/refactoring/typeMigration/t124/after/Test.items
java/typeMigration/testData/refactoring/typeMigration/t124/after/test.java
java/typeMigration/testData/refactoring/typeMigration/t125/after/Test.items
java/typeMigration/testData/refactoring/typeMigration/t125/after/test.java
java/typeMigration/testData/refactoring/typeMigration/t140/after/Test.items [new file with mode: 0644]
java/typeMigration/testData/refactoring/typeMigration/t140/after/test.java [new file with mode: 0644]
java/typeMigration/testData/refactoring/typeMigration/t140/before/test.java [new file with mode: 0644]
jps/jps-builders/testSrc/org/jetbrains/jps/builders/ModuleClasspathTest.kt
jps/jps-builders/testSrc/org/jetbrains/jps/builders/rebuild/JpsRebuildTestCase.kt
jps/model-impl/jps-model-tests.iml
jps/model-serialization/jps-serialization-tests.iml
jps/standalone-builder/src/org/jetbrains/jps/gant/JpsGantProjectBuilder.java
platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/FileStatusMap.java
platform/analysis-impl/src/com/intellij/packageDependencies/BackwardDependenciesBuilder.java
platform/core-api/src/com/intellij/diagnostic/IdePerformanceListener.java [new file with mode: 0644]
platform/core-api/src/com/intellij/openapi/command/WriteCommandAction.java
platform/core-api/src/com/intellij/openapi/vfs/VfsUtilCore.java
platform/core-api/src/com/intellij/psi/tree/IElementType.java
platform/core-impl/src/com/intellij/diagnostic/PerformanceWatcher.java
platform/core-impl/src/com/intellij/openapi/components/impl/ComponentManagerImpl.java
platform/core-impl/src/com/intellij/openapi/editor/ex/DocumentEx.java
platform/core-impl/src/com/intellij/openapi/editor/impl/RangeMarkerTree.java
platform/core-impl/src/com/intellij/openapi/editor/impl/RedBlackTree.java
platform/core-impl/src/com/intellij/openapi/progress/impl/CoreProgressManager.java
platform/core-impl/src/com/intellij/openapi/progress/impl/NonCancelableIndicator.java
platform/core-impl/src/com/intellij/openapi/vfs/impl/VirtualFilePointerContainerImpl.java
platform/core-impl/src/com/intellij/util/CachedValueChecker.java
platform/core-impl/src/com/intellij/util/CachedValuesManagerImpl.java
platform/core-impl/src/com/intellij/util/DebugReflectionUtil.java [new file with mode: 0644]
platform/diff-api/src/com/intellij/diff/fragments/DiffFragmentImpl.java
platform/diff-api/src/com/intellij/diff/fragments/LineFragmentImpl.java
platform/diff-impl/diff-tests.iml
platform/diff-impl/src/com/intellij/diff/DiffContentFactoryImpl.java
platform/diff-impl/src/com/intellij/diff/DiffManagerImpl.java
platform/diff-impl/src/com/intellij/diff/DiffRequestFactoryImpl.java
platform/diff-impl/src/com/intellij/diff/actions/BaseShowDiffAction.java
platform/diff-impl/src/com/intellij/diff/actions/CompareFilesAction.java
platform/diff-impl/src/com/intellij/diff/applications/DiffApplication.java
platform/diff-impl/src/com/intellij/diff/applications/MergeApplication.java
platform/diff-impl/src/com/intellij/diff/comparison/ByLine.java
platform/diff-impl/src/com/intellij/diff/comparison/ChangeCorrector.java
platform/diff-impl/src/com/intellij/diff/comparison/ComparisonManagerImpl.java
platform/diff-impl/src/com/intellij/diff/contents/FileAwareDocumentContent.java
platform/diff-impl/src/com/intellij/diff/contents/FileDocumentContentImpl.java
platform/diff-impl/src/com/intellij/diff/fragments/MergeLineFragmentImpl.java
platform/diff-impl/src/com/intellij/diff/fragments/MergeWordFragmentImpl.java
platform/diff-impl/src/com/intellij/diff/impl/CacheDiffRequestChainProcessor.java
platform/diff-impl/src/com/intellij/diff/impl/DiffSettingsHolder.java
platform/diff-impl/src/com/intellij/diff/merge/TextMergeChange.java
platform/diff-impl/src/com/intellij/diff/merge/TextMergeTool.java
platform/diff-impl/src/com/intellij/diff/statistics/DiffUsagesCollector.java
platform/diff-impl/src/com/intellij/diff/tools/external/ExternalDiffSettings.java
platform/diff-impl/src/com/intellij/diff/tools/fragmented/UnifiedDiffViewer.java
platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffViewer.java
platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleThreesideDiffViewer.java
platform/diff-impl/src/com/intellij/diff/tools/simple/ThreesideTextDiffViewerEx.java
platform/diff-impl/src/com/intellij/diff/tools/util/BaseSyncScrollable.java
platform/diff-impl/src/com/intellij/diff/tools/util/FocusTrackerSupport.java
platform/diff-impl/src/com/intellij/diff/tools/util/ThreeDiffSplitter.java
platform/diff-impl/src/com/intellij/diff/tools/util/base/DiffViewerBase.java
platform/diff-impl/src/com/intellij/diff/tools/util/base/InitialScrollPositionSupport.java
platform/diff-impl/src/com/intellij/diff/tools/util/base/TextDiffSettingsHolder.java
platform/diff-impl/src/com/intellij/diff/tools/util/base/TextDiffViewerUtil.java
platform/diff-impl/src/com/intellij/diff/util/DiffGutterRenderer.java
platform/diff-impl/src/com/intellij/diff/util/DiffUtil.java
platform/diff-impl/tests/com/intellij/diff/tools/util/PrevNextIterableTest.kt [new file with mode: 0644]
platform/lang-impl/src/com/intellij/codeInsight/actions/LayoutProjectCodeDialog.java
platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeAction.java
platform/lang-impl/src/com/intellij/codeInspection/actions/FileFilterPanel.java
platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java
platform/lang-impl/src/com/intellij/find/impl/FindDialog.java
platform/lang-impl/src/com/intellij/find/impl/FindInProjectTask.java
platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java
platform/lang-impl/src/com/intellij/find/impl/FindManagerImpl.java
platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java
platform/lang-impl/src/com/intellij/ide/projectView/impl/AbstractProjectViewPane.java
platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java
platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/AbstractModuleNode.java
platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/NamedLibraryElementNode.java
platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/PsiDirectoryNode.java
platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/PsiFileNode.java
platform/lang-impl/src/com/intellij/ide/util/projectWizard/AbstractNewProjectStep.java
platform/lang-impl/src/com/intellij/ide/util/projectWizard/EmptyWebProjectTemplate.java [new file with mode: 0644]
platform/lang-impl/src/com/intellij/moduleDependencies/DependenciesAnalyzeManager.java
platform/lang-impl/src/com/intellij/moduleDependencies/ModulesDependenciesPanel.java
platform/lang-impl/src/com/intellij/moduleDependencies/ShowModuleDependenciesAction.java
platform/lang-impl/src/com/intellij/packageDependencies/actions/AnalyzeDependenciesOnSpecifiedTargetHandler.java
platform/lang-impl/src/com/intellij/packageDependencies/actions/DependenciesHandlerBase.java
platform/lang-impl/src/com/intellij/packageDependencies/ui/ModuleNode.java
platform/platform-api/src/com/intellij/openapi/actionSystem/IdeActions.java
platform/platform-api/src/com/intellij/openapi/command/undo/UndoManager.java
platform/platform-api/src/com/intellij/openapi/ui/TextFieldWithBrowseButton.java
platform/platform-api/src/com/intellij/ui/table/JBTable.java
platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.java
platform/platform-api/src/com/intellij/util/ui/ButtonlessScrollBarUI.java
platform/platform-impl/src/com/intellij/diagnostic/DefaultIdeaErrorLogger.java
platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ToolbarUpdater.java
platform/platform-impl/src/com/intellij/openapi/application/impl/LaterInvocator.java
platform/platform-impl/src/com/intellij/openapi/command/impl/CommandMerger.java
platform/platform-impl/src/com/intellij/openapi/command/impl/NonUndoableAction.java
platform/platform-impl/src/com/intellij/openapi/command/impl/UndoManagerImpl.java
platform/platform-impl/src/com/intellij/openapi/diff/impl/GenericDataProvider.java
platform/platform-impl/src/com/intellij/openapi/editor/impl/ComplementaryFontsRegistry.java
platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java
platform/platform-impl/src/com/intellij/openapi/editor/impl/SoftWrapModelImpl.java
platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorCoordinateMapper.java
platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorPainter.java
platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorSizeManager.java
platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorView.java
platform/platform-impl/src/com/intellij/openapi/editor/impl/view/LineLayout.java
platform/platform-impl/src/com/intellij/openapi/editor/impl/view/LogicalPositionCache.java
platform/platform-impl/src/com/intellij/openapi/editor/impl/view/TextLayoutCache.java
platform/platform-impl/src/com/intellij/openapi/editor/impl/view/VisualLineFragmentsIterator.java
platform/platform-impl/src/com/intellij/openapi/editor/impl/view/VisualLinesIterator.java [new file with mode: 0644]
platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/PluginDownloader.java
platform/platform-resources-en/platform-resources-en.iml
platform/platform-resources-en/src/messages/ActionsBundle.properties
platform/platform-resources-en/src/messages/AnalysisScopeBundle.properties
platform/platform-resources-en/src/messages/InspectionsBundle.properties
platform/platform-resources-en/src/messages/UIBundle.properties
platform/platform-resources/platform-resources.iml
platform/platform-tests/testSrc/com/intellij/openapi/application/impl/LaterInvocatorTest.java
platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorPaintingTest.java
platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/AbstractEditorTest.java
platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorImplTest.java
platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorViewAccessor.java [new file with mode: 0644]
platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/RangeMarkerTest.java
platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/softwrap/mapping/SoftWrapStressTest.java [deleted file]
platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/view/VisualLinesIteratorTest.java [new file with mode: 0644]
platform/platform-tests/testSrc/com/intellij/openapi/progress/impl/ProgressIndicatorTest.java
platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilTest.java
platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTest.java
platform/platform-tests/testSrc/com/intellij/util/io/PersistentMapTestBase.java
platform/platform-tests/testSrc/com/intellij/util/messages/MessageBusTest.java
platform/platform-tests/testSrc/com/intellij/util/net/ssl/CertificateTest.java
platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootModelBase.java
platform/smRunner/src/com/intellij/execution/testframework/sm/runner/SMTestProxy.java
platform/smRunner/src/com/intellij/execution/testframework/sm/runner/history/actions/AbstractImportTestsAction.java
platform/smRunner/testSrc/com/intellij/execution/testframework/sm/OutputLineSplitterTest.java
platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/SMTestProxyTest.java
platform/structuralsearch/source/com/intellij/structuralsearch/DefaultMatchResultSink.java [new file with mode: 0644]
platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/MatcherImpl.java
platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/DeleteNodesAction.java
platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/GlobalCompilingVisitor.java
platform/structuralsearch/source/com/intellij/structuralsearch/plugin/util/CollectingMatchResultSink.java
platform/structuralsearch/structuralsearch-tests.iml
platform/testFramework/src/com/intellij/testFramework/LeakHunter.java
platform/util/src/com/intellij/diagnostic/ThreadDump.java [new file with mode: 0644]
platform/util/src/com/intellij/diagnostic/ThreadDumper.java
platform/util/src/com/intellij/openapi/util/Disposer.java
platform/util/src/com/intellij/util/Processor.java
platform/util/testSrc/com/intellij/openapi/util/objectTree/DisposerTest.java
platform/vcs-api/src/com/intellij/openapi/vcs/ProjectLevelVcsManager.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/RollbackAction.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/diff/ChangeDiffRequestProducer.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTreeList.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/RollbackChangesDialog.java
platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java
platform/vcs-log/graph/test/com/intellij/vcs/log/graph/TestGraphBuilder.kt
platform/vcs-log/impl/test/com/intellij/vcs/log/data/VcsLogJoinerTest.kt
plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/StringBufferReplaceableByStringInspectionBase.java [new file with mode: 0644]
plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/visibility/ParameterHidingMemberVariableInspectionBase.java
plugins/InspectionGadgets/src/com/siyeh/ig/style/StringBufferReplaceableByStringInspection.java [moved from plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/StringBufferReplaceableByStringInspection.java with 51% similarity]
plugins/InspectionGadgets/src/inspectionDescriptions/ParameterHidingMemberVariable.html
plugins/InspectionGadgets/src/inspectionDescriptions/SimplifiableBooleanExpression.html
plugins/InspectionGadgets/test/com/siyeh/igtest/visibility/parameter_hiding_member_variable/ParameterHidingMemberVariable.java
plugins/InspectionGadgets/test/com/siyeh/igtest/visibility/parameter_hiding_member_variable/expected.xml [deleted file]
plugins/InspectionGadgets/testsrc/com/siyeh/ig/visibility/ParameterHidingMemberVariableInspectionTest.java
plugins/coverage-common/src/com/intellij/coverage/view/DirectoryCoverageViewExtension.java
plugins/coverage/src/com/intellij/coverage/IDEACoverageRunner.java
plugins/coverage/src/com/intellij/coverage/JavaCoverageRunner.java
plugins/devkit/testSources/PluginProjectWizardTest.java
plugins/generate-tostring/src/org/jetbrains/java/generate/template/toString/DefaultConcatMemberSuperGroovy.vm [new file with mode: 0644]
plugins/generate-tostring/src/org/jetbrains/java/generate/template/toString/ToStringTemplatesManager.java
plugins/git4idea/src/git4idea/GitVcs.java
plugins/git4idea/src/git4idea/ui/branch/GitLogBranchOperationsActionGroup.java
plugins/gradle/testSources/org/jetbrains/plugins/gradle/GradleProjectWizardTest.java
plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/ExternalProjectBuilderImpl.groovy
plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/util/DependencyResolverImpl.groovy
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/GrTraitType.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceResolveRunner.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrWithTraitTypeCalculator.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/types/GrSafeCastExpressionImpl.java
plugins/groovy/src/META-INF/plugin.xml
plugins/groovy/src/org/jetbrains/plugins/groovy/actions/generate/tostring/GroovyGenerateToStringAction.java [new file with mode: 0644]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/CompleteReferenceExpression.java
plugins/groovy/test/org/jetbrains/plugins/groovy/lang/actions/generate/GroovyGenerateActionsTest.groovy [new file with mode: 0644]
plugins/hg4idea/src/META-INF/plugin.xml
plugins/hg4idea/src/org/zmlx/hg4idea/HgVFSListener.java
plugins/hg4idea/src/org/zmlx/hg4idea/HgVcs.java
plugins/hg4idea/src/org/zmlx/hg4idea/action/HgMergeWithRevisionFromLog.java [new file with mode: 0644]
plugins/hg4idea/src/org/zmlx/hg4idea/command/HgMergeCommand.java
plugins/hg4idea/src/org/zmlx/hg4idea/execution/HgCommandExecutor.java
plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/ClassWriter.java
plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/ClassesProcessor.java
plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/collectors/BytecodeMappingTracer.java
plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java
plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java
plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/struct/attr/StructInnerClassesAttribute.java
plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/util/InterpreterUtil.java
plugins/java-decompiler/engine/testData/classes/pkg/TestInnerClassConstructor$1.class
plugins/java-decompiler/engine/testData/classes/pkg/TestInnerClassConstructor$Another.class [new file with mode: 0644]
plugins/java-decompiler/engine/testData/classes/pkg/TestInnerClassConstructor$Inner.class
plugins/java-decompiler/engine/testData/classes/pkg/TestInnerClassConstructor.class
plugins/java-decompiler/engine/testData/classes/v11/TestInnerClassConstructor$1.class
plugins/java-decompiler/engine/testData/classes/v11/TestInnerClassConstructor$Another.class [new file with mode: 0644]
plugins/java-decompiler/engine/testData/classes/v11/TestInnerClassConstructor$Inner.class
plugins/java-decompiler/engine/testData/classes/v11/TestInnerClassConstructor.class
plugins/java-decompiler/engine/testData/results/TestInnerClassConstructor.dec
plugins/java-decompiler/engine/testData/src/pkg/TestInnerClassConstructor.java
plugins/maven/src/test/java/org/jetbrains/idea/maven/execution/MavenRunConfigurationTest.java
plugins/maven/src/test/java/org/jetbrains/idea/maven/indices/MavenIndicesStressTest.java
plugins/maven/src/test/java/org/jetbrains/idea/maven/plugins/MavenParameterGoalTest.java
plugins/maven/src/test/java/org/jetbrains/idea/maven/tests/MavenSurefireReportInConsoleTest.java
plugins/maven/src/test/java/org/jetbrains/idea/maven/utils/MavenTemplateFileProcessorTest.java
plugins/maven/src/test/java/org/jetbrains/idea/maven/wizards/MavenImportWizardTest.java
plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnBusyOnAddTest.java
plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnCachingRepositoryPoolTest.java
plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnLockingTest.java
plugins/svn4idea/testSource/org/jetbrains/idea/svn/VcsWaitForUpdateForTest.java
plugins/svn4idea/testSource/org/jetbrains/idea/svn16/VcsWaitForUpdateForTest.java
plugins/tasks/tasks-core/src/com/intellij/tasks/actions/OpenTaskDialog.java
plugins/testng/src/com/theoryinpractice/testng/configuration/AbstractTestNGInClassConfigurationProducer.java
python/helpers/pydev/pydev_ipython_console_011.py
python/ide/src/com/jetbrains/python/newProject/actions/PyCharmNewProjectStep.java
python/openapi/src/com/jetbrains/python/templateLanguages/PyTemplatesUtil.java
python/pluginSrc/com/jetbrains/python/packaging/PyManagePackagesDialog.java
python/psi-api/src/com/jetbrains/python/psi/types/TypeEvalContext.java
python/pydevSrc/com/jetbrains/python/debugger/IPyDebugProcess.java
python/pydevSrc/com/jetbrains/python/debugger/pydev/RemoteDebugger.java
python/python-rest/resources/META-INF/plugin.xml
python/python-rest/src/com/jetbrains/rest/sphinx/SphinxBaseCommand.java
python/src/com/jetbrains/python/codeInsight/testIntegration/PyTestCreator.java
python/src/com/jetbrains/python/console/PydevConsoleRunner.java
python/src/com/jetbrains/python/documentation/docstrings/DocStringParameterReference.java
python/src/com/jetbrains/python/documentation/docstrings/DocStringReferenceProvider.java
python/src/com/jetbrains/python/inspections/PyIncorrectDocstringInspection.java
python/src/com/jetbrains/python/run/PythonCommandLineState.java
python/testData/inspections/GoogleDocstringParametersInspection/test.py
python/testData/inspections/PyDocstringParametersInspection/test.py
python/testData/resolve/GoogleDocstringModuleAttribute.py [new file with mode: 0644]
python/testSrc/com/jetbrains/env/python/console/PyConsoleTask.java
python/testSrc/com/jetbrains/env/python/debug/PyBaseDebuggerTask.java
python/testSrc/com/jetbrains/python/PyAddImportTest.java
python/testSrc/com/jetbrains/python/PyMultiFileResolveTest.java
python/testSrc/com/jetbrains/python/PyQuickFixTest.java
python/testSrc/com/jetbrains/python/PyResolveTest.java
python/testSrc/com/jetbrains/python/fixtures/PyMultiFileResolveTestCase.java
python/testSrc/com/jetbrains/python/fixtures/PyResolveTestCase.java
python/testSrc/python-community-tests.iml
spellchecker/src/com/intellij/spellchecker/english.dic
xml/dom-tests/dom-tests.iml
xml/dom-tests/tests/com/intellij/util/xml/DomConcurrencyStressTest.java
xml/relaxng/src/org/intellij/plugins/relaxNG/validation/RngParser.java
xml/tests/xml-tests.iml

index f0cc42032920d3521a5f08602e76668625ea2524..59860660a3eddb0fe550e0f751a77b54e1c468f3 100644 (file)
         <processorPath useClasspath="true" />
       </profile>
     </annotationProcessing>
-    <bytecodeTargetLevel target="1.6">
-      <module name="annotations" target="1.5" />
-      <module name="annotations-common" target="1.5" />
-      <module name="annotations-java8" target="1.8" />
-      <module name="community-tests" target="1.8" />
-      <module name="configuration-store-tests" target="1.8" />
-      <module name="diff-tests" target="1.8" />
-      <module name="gradle-jps-plugin" target="1.6" />
-      <module name="groovy-rt-constants" target="1.5" />
-      <module name="groovy_rt" target="1.5" />
-      <module name="intellilang-jps-plugin" target="1.6" />
-      <module name="IntelliLang-tests" target="1.8" />
+    <bytecodeTargetLevel>
       <module name="java-runtime" target="1.1" />
-      <module name="java-tests" target="1.8" />
-      <module name="javac2" target="1.5" />
-      <module name="javaFX-jps-plugin" target="1.6" />
-      <module name="jps-builders" target="1.6" />
-      <module name="jps-launcher" target="1.6" />
-      <module name="jps-model-api" target="1.6" />
-      <module name="jps-model-impl" target="1.6" />
-      <module name="jps-model-serialization" target="1.6" />
-      <module name="jps-standalone-builder" target="1.6" />
-      <module name="json-tests" target="1.8" />
       <module name="junit_rt" target="1.1" />
-      <module name="lang-tests" target="1.8" />
-      <module name="maven-jps-plugin" target="1.6" />
-      <module name="platform-tests" target="1.8" />
-      <module name="remote-servers-agent-rt" target="1.5" />
-      <module name="svn4idea-tests" target="1.8" />
-      <module name="tasks-tests" target="1.8" />
-      <module name="testng_rt" target="1.5" />
-      <module name="ui-designer-jps-plugin" target="1.6" />
-      <module name="util-rt" target="1.6" />
     </bytecodeTargetLevel>
   </component>
   <component name="EclipseCompilerSettings">
index 032c87b1619918040d3fe25e4aa95dda81f3e827..ec0fc157ae0fcc3f606ad90b39773db1b97700f6 100644 (file)
@@ -4,16 +4,19 @@
 ; each line represent a patching rule
 ;
 ;  - => path
-;     this is exclude rule. It excludes all paths that starts with given prefix
+;     this is exclude rule. It excludes all paths that starts with given prefix,
+;     longer path include rule overcomes exclude rule
 ;  xx => path
-;     this is the rule to enforce check of java classes of version xx, where xx could
-;     be one of the following: 1.2, 1.3, 1.4, 1.5, 1.6, 1.7
+;     this is the rule to check that java classes under given path of version xx or older, where xx could
+;     be one of the following: 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8
 ;  check static => path
 ;     this is the rule to check static class usages in classes under given path
 ;  - check static => path
 ;     exclude following paths from the check
 ;  allow static class NAME
 ;     allow use of given class (by starts-with) from static context
+;  include path
+;     include content of path (it is relative to the parent directory of current config file) into this file
 ;
 ;  see example below
 ;
 ;  have fun
 ;
 
-
 1.6 =>
 
 1.3 => lib/idea_rt.jar
+1.4 => lib/forms_rt.jar
 
 1.7 => lib/optimizedFileManager.jar
 
 1.5 => plugins/Groovy/lib/groovy_rt.jar
+1.5 => plugins/Groovy/lib/groovy-rt-constants.jar
+1.5 => plugins/coverage/lib/coverage_rt.jar
 1.5 => lib/annotations.jar
 1.8 => redist/annotations-java8.jar
-
-1.6 => plugins/gradle/lib/gradle-jps-plugin.jar
-
 1.3 => plugins/junit/lib/junit-rt.jar
index 47dae3ce4e4be83f235f2a65f2d33961b765df0e..4f8749b4a9e592e42cdc3bde887c2f05b38479b8 100644 (file)
Binary files a/build/lib/jps/antlayout.jar and b/build/lib/jps/antlayout.jar differ
index a4c8f681c0f62f2d1119acb66beb6c7de9ad3243..4b110fe925641fe75ab1bea9defa7cf773b22029 100644 (file)
Binary files a/build/lib/jps/groovy-jps-plugin.jar and b/build/lib/jps/groovy-jps-plugin.jar differ
diff --git a/build/lib/jps/groovy-rt-constants.jar b/build/lib/jps/groovy-rt-constants.jar
new file mode 100644 (file)
index 0000000..4942911
Binary files /dev/null and b/build/lib/jps/groovy-rt-constants.jar differ
index f74f0a8d04da643985cc1a0fddbff031f53f9e96..b6b715af6854cb4082e1240c228b0fc856f6abd5 100644 (file)
Binary files a/build/lib/jps/groovy_rt.jar and b/build/lib/jps/groovy_rt.jar differ
index 6a7921340299bc05cc2387b86f2c1e9f3a19cf8d..92b74182f5e6684107a0fae02c623cc681871b05 100644 (file)
Binary files a/build/lib/jps/jps-builders.jar and b/build/lib/jps/jps-builders.jar differ
index 3d4fc269fb0f53e14fb4b88a926c05610a05a545..b6aec1fce8b22308d0241b42962ccf5c6650d239 100644 (file)
Binary files a/build/lib/jps/jps-model.jar and b/build/lib/jps/jps-model.jar differ
index 43351b53937977b391d05d82ff0e8df5291b3176..fcb2cc6a7695157f3a7adf0772936811ee9c9ecd 100644 (file)
Binary files a/build/lib/jps/ui-designer-jps-plugin.jar and b/build/lib/jps/ui-designer-jps-plugin.jar differ
index 18195e67fe21f66879e25d10f916b1eb5a44439e..16c6232dcae65194eea0683915c8056f27c46568 100644 (file)
Binary files a/build/lib/jps/util.jar and b/build/lib/jps/util.jar differ
index c053808175a3403f411f4b01719927b491283c5e..47b8d551b85eb8d277f49d359ee2e810fe633c94 100644 (file)
@@ -3,10 +3,9 @@
   <component name="NewModuleRootManager" inherit-compiler-output="true">
     <exclude-output />
     <content url="file://$MODULE_DIR$">
-      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src" type="java-resource" />
     </content>
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />
   </component>
-</module>
-
+</module>
\ No newline at end of file
index 32223aaaf3e6ea45ecab473cefdb37c01580a876..5c886d1ea7cfa3a90b150b4f90af841f7d52b5d3 100644 (file)
@@ -16,6 +16,7 @@
 package com.intellij.execution.testDiscovery;
 
 import com.intellij.application.options.ModulesComboBox;
+import com.intellij.execution.ExecutionBundle;
 import com.intellij.execution.MethodBrowser;
 import com.intellij.execution.ui.*;
 import com.intellij.ide.util.ClassFilter;
@@ -61,7 +62,7 @@ public class TestDiscoveryConfigurable<T extends TestDiscoveryConfiguration> ext
   private JComponent anchor;
 
   public TestDiscoveryConfigurable(final Project project) {
-    myModule.setText("Use classpath of");
+    myModule.setText(ExecutionBundle.message("application.configuration.use.classpath.and.jdk.of.module.label"));
     myModule.setLabelLocation(BorderLayout.WEST);
     myModule.setComponent(new ModulesComboBox());
     myModuleSelector = new ConfigurationModuleSelector(project, getModulesComponent());
index 973ffa59426cfc72b14e37cec74e736b8b9789df..e1374f446c7e68dd55b7478088df533eb7add679 100644 (file)
@@ -109,7 +109,8 @@ public class SaveProjectAsTemplateAction extends AnAction {
   }
 
   public static VirtualFile getDescriptionFile(Project project, String path) {
-    return VfsUtilCore.findRelativeFile(path, project.getBaseDir());
+    VirtualFile baseDir = project.getBaseDir();
+    return baseDir != null ? baseDir.findFileByRelativePath(path) : null;
   }
 
   public static void saveProject(final Project project,
index 333b633b7ac1b518d0f2a69ee6f7d9a10d03991a..c24803d73a41a201c8c608d9b4078253184a356e 100644 (file)
@@ -71,7 +71,14 @@ public class GenericsHighlightUtil {
   static HighlightInfo checkInferredTypeArguments(PsiTypeParameter[] typeParameters,
                                                   PsiElement call,
                                                   PsiSubstitutor substitutor) {
-    final Pair<PsiTypeParameter, PsiType> inferredTypeArgument = GenericsUtil.findTypeParameterWithBoundError(typeParameters, substitutor, call, false);
+    return checkInferredTypeArguments(typeParameters, call, substitutor, false);
+  }
+
+  @Nullable
+  static HighlightInfo checkInferredTypeArguments(PsiTypeParameter[] typeParameters,
+                                                  PsiElement call,
+                                                  PsiSubstitutor substitutor, boolean allowUncheckedConversion) {
+    final Pair<PsiTypeParameter, PsiType> inferredTypeArgument = GenericsUtil.findTypeParameterWithBoundError(typeParameters, substitutor, call, allowUncheckedConversion);
     if (inferredTypeArgument != null) {
       final PsiType extendsType = inferredTypeArgument.second;
       final PsiTypeParameter typeParameter = inferredTypeArgument.first;
index cd74075c5c0ed3da81f4cbdeb31396368bb8a01a..2d3c1218afb07d8d6605055c0c586a4b726fd62f 100644 (file)
@@ -1341,7 +1341,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
         assert containingClass != null : method;
         typeParameters = ArrayUtil.mergeArrays(typeParameters, containingClass.getTypeParameters());
       }
-      myHolder.add(GenericsHighlightUtil.checkInferredTypeArguments(typeParameters, expression, result.getSubstitutor()));
+      myHolder.add(GenericsHighlightUtil.checkInferredTypeArguments(typeParameters, expression, result.getSubstitutor(), true));
     }
 
     if (!myHolder.hasErrorResults()) {
index 7b1af3b24ae9d13e43527a8ed94a7f7572a95d20..01239024a52b3be1707c0464ccd343cd4c9e3474 100644 (file)
@@ -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.
@@ -63,6 +63,7 @@ public class ExpressionTypeMemoryState extends DfaMemoryStateImpl {
     super(toCopy);
   }
 
+  @NotNull
   @Override
   public DfaMemoryStateImpl createCopy() {
     final ExpressionTypeMemoryState copy = new ExpressionTypeMemoryState(this);
index b7e4660e5260a6b368dd5be7b2e2bdc357ff2af5..65be476e4b3e58bd19b015472148b661ec5094cf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2013 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,10 +17,10 @@ package com.intellij.codeInsight.guess.impl;
 
 import com.intellij.codeInsight.guess.GuessManager;
 import com.intellij.codeInspection.dataFlow.*;
-import com.intellij.codeInspection.dataFlow.instructions.PushInstruction;
-import com.intellij.codeInspection.dataFlow.instructions.TypeCastInstruction;
 import com.intellij.codeInspection.dataFlow.instructions.InstanceofInstruction;
 import com.intellij.codeInspection.dataFlow.instructions.MethodCallInstruction;
+import com.intellij.codeInspection.dataFlow.instructions.PushInstruction;
+import com.intellij.codeInspection.dataFlow.instructions.TypeCastInstruction;
 import com.intellij.codeInspection.dataFlow.value.DfaInstanceofValue;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.TextRange;
@@ -31,8 +31,8 @@ import com.intellij.psi.search.PsiElementProcessorAdapter;
 import com.intellij.psi.search.SearchScope;
 import com.intellij.psi.search.searches.ClassInheritorsSearch;
 import com.intellij.psi.search.searches.ReferencesSearch;
-import com.intellij.psi.util.PsiUtil;
 import com.intellij.psi.util.PsiTreeUtil;
+import com.intellij.psi.util.PsiUtil;
 import com.intellij.util.containers.ContainerUtil;
 import gnu.trove.THashMap;
 import org.jetbrains.annotations.NotNull;
@@ -151,6 +151,7 @@ public class GuessManagerImpl extends GuessManager {
     }
 
     DataFlowRunner runner = new DataFlowRunner() {
+      @NotNull
       @Override
       protected DfaMemoryState createMemoryState() {
         return new ExpressionTypeMemoryState(getFactory());
index a7e41a910892c10e826fa32e98dac833b9cc8b8e..ad1fc779e46b2a16442cd74d2f2e3c674f20a556 100644 (file)
@@ -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.
@@ -25,6 +25,7 @@ import com.intellij.codeInspection.dataFlow.value.DfaValueFactory;
 import com.intellij.codeInspection.dataFlow.value.DfaVariableValue;
 import com.intellij.psi.*;
 import com.intellij.util.containers.ContainerUtil;
+import org.jetbrains.annotations.NotNull;
 
 import java.util.*;
 
@@ -39,7 +40,7 @@ class ContractChecker extends DataFlowRunner {
   private final Set<PsiElement> myNonViolations = ContainerUtil.newHashSet();
   private final Set<PsiElement> myFailures = ContainerUtil.newHashSet();
 
-  ContractChecker(PsiMethod method, MethodContract contract, final boolean onTheFly) {
+  private ContractChecker(PsiMethod method, MethodContract contract, final boolean onTheFly) {
     myMethod = method;
     myContract = contract;
     myOnTheFly = onTheFly;
@@ -77,8 +78,9 @@ class ContractChecker extends DataFlowRunner {
     return super.shouldCheckTimeLimit();
   }
 
+  @NotNull
   @Override
-  protected DfaInstructionState[] acceptInstruction(InstructionVisitor visitor, DfaInstructionState instructionState) {
+  protected DfaInstructionState[] acceptInstruction(@NotNull InstructionVisitor visitor, @NotNull DfaInstructionState instructionState) {
     DfaMemoryState memState = instructionState.getMemoryState();
     if (memState.isEphemeral()) {
       return DfaInstructionState.EMPTY_ARRAY;
index 1adc7fa781d2928545952aa1d7faba17781279df..ec8fbf673817239cef5b438e672be02870945a8a 100644 (file)
@@ -52,11 +52,12 @@ public class DataFlowRunner {
 
   private Instruction[] myInstructions;
   private final MultiMap<PsiElement, DfaMemoryState> myNestedClosures = new MultiMap<PsiElement, DfaMemoryState>();
+  @NotNull
   private final DfaValueFactory myValueFactory;
 
   // Maximum allowed attempts to process instruction. Fail as too complex to process if certain instruction
   // is executed more than this limit times.
-  public static final int MAX_STATES_PER_BRANCH = 300;
+  static final int MAX_STATES_PER_BRANCH = 300;
 
   protected DataFlowRunner() {
     this(false, true);
@@ -66,12 +67,13 @@ public class DataFlowRunner {
     myValueFactory = new DfaValueFactory(honorFieldInitializers, unknownMembersAreNullable);
   }
 
+  @NotNull
   public DfaValueFactory getFactory() {
     return myValueFactory;
   }
 
   @Nullable
-  private Collection<DfaMemoryState> createInitialStates(@NotNull PsiElement psiBlock, InstructionVisitor visitor) {
+  private Collection<DfaMemoryState> createInitialStates(@NotNull PsiElement psiBlock, @NotNull InstructionVisitor visitor) {
     PsiClass containingClass = PsiTreeUtil.getParentOfType(psiBlock, PsiClass.class);
     if (containingClass != null && PsiUtil.isLocalOrAnonymousClass(containingClass)) {
       final PsiElement parent = containingClass.getParent();
@@ -91,16 +93,17 @@ public class DataFlowRunner {
     return Collections.singletonList(createMemoryState());
   }
 
-  public final RunnerResult analyzeMethod(@NotNull PsiElement psiBlock, InstructionVisitor visitor) {
+  @NotNull
+  public final RunnerResult analyzeMethod(@NotNull PsiElement psiBlock, @NotNull InstructionVisitor visitor) {
     Collection<DfaMemoryState> initialStates = createInitialStates(psiBlock, visitor);
     return initialStates == null ? RunnerResult.NOT_APPLICABLE : analyzeMethod(psiBlock, visitor, false, initialStates);
   }
 
   @NotNull
-  public final RunnerResult analyzeMethod(@NotNull PsiElement psiBlock,
-                                          InstructionVisitor visitor,
-                                          boolean ignoreAssertions,
-                                          @NotNull Collection<DfaMemoryState> initialStates) {
+  final RunnerResult analyzeMethod(@NotNull PsiElement psiBlock,
+                                   @NotNull InstructionVisitor visitor,
+                                   boolean ignoreAssertions,
+                                   @NotNull Collection<DfaMemoryState> initialStates) {
     if (PsiTreeUtil.findChildOfType(psiBlock, OuterLanguageElement.class) != null) return RunnerResult.NOT_APPLICABLE;
 
     try {
@@ -127,7 +130,7 @@ public class DataFlowRunner {
       if (LOG.isDebugEnabled()) {
         LOG.debug("Analyzing code block: " + psiBlock.getText());
         for (int i = 0; i < myInstructions.length; i++) {
-          LOG.debug(i + ": " + myInstructions[i].toString());
+          LOG.debug(i + ": " + myInstructions[i]);
         }
       }
       //for (int i = 0; i < myInstructions.length; i++) System.out.println(i + ": " + myInstructions[i].toString());
@@ -220,10 +223,11 @@ public class DataFlowRunner {
   private void handleStepOutOfLoop(@NotNull final Instruction prevInstruction,
                                    @NotNull Instruction nextInstruction,
                                    @NotNull final int[] loopNumber,
-                                   MultiMap<BranchingInstruction, DfaMemoryState> processedStates,
-                                   MultiMap<BranchingInstruction, DfaMemoryState> incomingStates,
-                                   List<DfaInstructionState> inFlightStates,
-                                   DfaInstructionState[] afterStates, StateQueue queue) {
+                                   @NotNull MultiMap<BranchingInstruction, DfaMemoryState> processedStates,
+                                   @NotNull MultiMap<BranchingInstruction, DfaMemoryState> incomingStates,
+                                   @NotNull List<DfaInstructionState> inFlightStates,
+                                   @NotNull DfaInstructionState[] afterStates,
+                                   @NotNull StateQueue queue) {
     if (loopNumber[prevInstruction.getIndex()] == 0 || inSameLoop(prevInstruction, nextInstruction, loopNumber)) {
       return;
     }
@@ -247,10 +251,7 @@ public class DataFlowRunner {
       @Override
       public boolean process(DfaInstructionState state) {
         Instruction instruction = state.getInstruction();
-        if (inSameLoop(prevInstruction, instruction, loopNumber)) {
-          return false;
-        }
-        return true;
+        return !inSameLoop(prevInstruction, instruction, loopNumber);
       }
     })) return;
 
@@ -276,7 +277,8 @@ public class DataFlowRunner {
     return !ApplicationManager.getApplication().isUnitTestMode();
   }
 
-  protected DfaInstructionState[] acceptInstruction(InstructionVisitor visitor, DfaInstructionState instructionState) {
+  @NotNull
+  protected DfaInstructionState[] acceptInstruction(@NotNull InstructionVisitor visitor, @NotNull DfaInstructionState instructionState) {
     Instruction instruction = instructionState.getInstruction();
     PsiElement closure = DfaUtil.getClosureInside(instruction);
     if (closure instanceof PsiClass) {
@@ -288,7 +290,7 @@ public class DataFlowRunner {
     return instruction.accept(this, instructionState.getMemoryState(), visitor);
   }
 
-  private void registerNestedClosures(DfaInstructionState instructionState, PsiClass nestedClass) {
+  private void registerNestedClosures(@NotNull DfaInstructionState instructionState, @NotNull PsiClass nestedClass) {
     DfaMemoryState state = instructionState.getMemoryState();
     for (PsiMethod method : nestedClass.getMethods()) {
       PsiCodeBlock body = method.getBody();
@@ -304,7 +306,7 @@ public class DataFlowRunner {
     }
   }
   
-  private void registerNestedClosures(DfaInstructionState instructionState, PsiLambdaExpression expr) {
+  private void registerNestedClosures(@NotNull DfaInstructionState instructionState, @NotNull PsiLambdaExpression expr) {
     DfaMemoryState state = instructionState.getMemoryState();
     PsiElement body = expr.getBody();
     if (body != null) {
@@ -312,22 +314,27 @@ public class DataFlowRunner {
     }
   }
 
+  @NotNull
   protected DfaMemoryState createMemoryState() {
     return new DfaMemoryStateImpl(myValueFactory);
   }
 
+  @NotNull
   public Instruction[] getInstructions() {
     return myInstructions;
   }
 
+  @NotNull
   public Instruction getInstruction(int index) {
     return myInstructions[index];
   }
 
-  public MultiMap<PsiElement, DfaMemoryState> getNestedClosures() {
+  @NotNull
+  MultiMap<PsiElement, DfaMemoryState> getNestedClosures() {
     return new MultiMap<PsiElement, DfaMemoryState>(myNestedClosures);
   }
 
+  @NotNull
   public Pair<Set<Instruction>,Set<Instruction>> getConstConditionalExpressions() {
     Set<Instruction> trueSet = new HashSet<Instruction>();
     Set<Instruction> falseSet = new HashSet<Instruction>();
@@ -362,7 +369,8 @@ public class DataFlowRunner {
     return Pair.create(trueSet, falseSet);
   }
 
-  private static DfaMemoryStateImpl createClosureState(DfaMemoryState memState) {
+  @NotNull
+  private static DfaMemoryStateImpl createClosureState(@NotNull DfaMemoryState memState) {
     DfaMemoryStateImpl copy = (DfaMemoryStateImpl)memState.createCopy();
     copy.flushFields();
     Set<DfaVariableValue> vars = new HashSet<DfaVariableValue>(copy.getVariableStates().keySet());
index 2fb0de1705e31c0719e1cb43d58cfd3644ae617d..326a7c76cf2189d7bd60de02951d44fb4d0b37f6 100644 (file)
@@ -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.
@@ -30,6 +30,7 @@ import org.jetbrains.annotations.Nullable;
  * To change this template use Options | File Templates.
  */
 public interface DfaMemoryState {
+  @NotNull
   DfaMemoryState createCopy();
 
   DfaValue pop();
@@ -40,7 +41,7 @@ public interface DfaMemoryState {
 
   void setVarValue(DfaVariableValue var, DfaValue value);
 
-  boolean applyInstanceofOrNull(DfaRelationValue dfaCond);
+  boolean applyInstanceofOrNull(@NotNull DfaRelationValue dfaCond);
 
   boolean applyCondition(DfaValue dfaCond);
 
@@ -55,7 +56,7 @@ public interface DfaMemoryState {
   boolean isNotNull(DfaValue dfaVar);
 
   @Nullable
-  DfaConstValue getConstantValue(DfaVariableValue value);
+  DfaConstValue getConstantValue(@NotNull DfaVariableValue value);
 
   /**
    * Ephemeral means a state that was created when considering a method contract and checking if one of its arguments is null.
index b015f5bfa80d726a6d31746b2b442bbb19264e5b..30eae15890a5380b2a9639bb6bb1354638ddac4b 100644 (file)
@@ -59,7 +59,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
   private final LinkedHashSet<DfaVariableValue> myUnknownVariables;
   private boolean myEphemeral;
 
-  public DfaMemoryStateImpl(final DfaValueFactory factory) {
+  protected DfaMemoryStateImpl(final DfaValueFactory factory) {
     myFactory = factory;
     myDefaultVariableStates = ContainerUtil.newTroveMap();
     myEqClasses = ContainerUtil.newArrayList();
@@ -95,10 +95,12 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
     myCachedHash = toCopy.myCachedHash;
   }
 
+  @NotNull
   public DfaValueFactory getFactory() {
     return myFactory;
   }
 
+  @NotNull
   @Override
   public DfaMemoryStateImpl createCopy() {
     return new DfaMemoryStateImpl(this);
@@ -112,7 +114,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
     return equalsSuperficially(that) && equalsByUnknownVariables(that) && equalsByRelations(that) && equalsByVariableStates(that);
   }
 
-  boolean equalsByUnknownVariables(DfaMemoryStateImpl that) {
+  private boolean equalsByUnknownVariables(DfaMemoryStateImpl that) {
     return myUnknownVariables.equals(that.myUnknownVariables);
   }
 
@@ -178,7 +180,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
     return hash;
   }
 
-  @SuppressWarnings({"HardCodedStringLiteral"})
+  @SuppressWarnings("HardCodedStringLiteral")
   public String toString() {
     StringBuilder result = new StringBuilder();
     result.append('<');
@@ -285,7 +287,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
   }
 
   @Nullable("for boxed values which can't be compared by ==")
-  private Integer getOrCreateEqClassIndex(DfaValue dfaValue) {
+  private Integer getOrCreateEqClassIndex(@NotNull DfaValue dfaValue) {
     int i = getEqClassIndex(dfaValue);
     if (i != -1) return i;
     if (!canBeInRelation(dfaValue) ||
@@ -340,7 +342,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
   }
 
 
-  private static boolean canBeInRelation(DfaValue dfaValue) {
+  private static boolean canBeInRelation(@NotNull DfaValue dfaValue) {
     DfaValue unwrapped = unwrap(dfaValue);
     return unwrapped instanceof DfaVariableValue || unwrapped instanceof DfaConstValue;
   }
@@ -393,7 +395,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
     return result;
   }
 
-  private boolean canBeReused(final DfaValue dfaValue) {
+  private boolean canBeReused(@NotNull DfaValue dfaValue) {
     if (dfaValue instanceof DfaBoxedValue) {
       DfaValue valueToWrap = ((DfaBoxedValue)dfaValue).getWrappedValue();
       if (valueToWrap instanceof DfaConstValue) {
@@ -410,12 +412,12 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
     return true;
   }
 
-  private static boolean cacheable(DfaConstValue dfaConstValue) {
+  private static boolean cacheable(@NotNull DfaConstValue dfaConstValue) {
     Object value = dfaConstValue.getValue();
     return box(value) == box(value);
   }
 
-  @SuppressWarnings({"UnnecessaryBoxing"})
+  @SuppressWarnings("UnnecessaryBoxing")
   private static Object box(final Object value) {
     Object newBoxedValue;
     if (value instanceof Integer) {
@@ -577,7 +579,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
 
   @Override
   @Nullable
-  public DfaConstValue getConstantValue(DfaVariableValue value) {
+  public DfaConstValue getConstantValue(@NotNull DfaVariableValue value) {
     int index = getEqClassIndex(value);
     EqClass ec = index == -1 ? null : myEqClasses.get(index);
     return ec == null ? null : (DfaConstValue)unwrap(ec.findConstant(true));
@@ -594,7 +596,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
   }
 
   @Override
-  public boolean applyInstanceofOrNull(DfaRelationValue dfaCond) {
+  public boolean applyInstanceofOrNull(@NotNull DfaRelationValue dfaCond) {
     DfaValue left = unwrap(dfaCond.getLeftOperand());
 
     if (!(left instanceof DfaVariableValue)) return true;
@@ -648,7 +650,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
     return applyRelationCondition((DfaRelationValue)dfaCond);
   }
 
-  private boolean applyRelationCondition(DfaRelationValue dfaRelation) {
+  private boolean applyRelationCondition(@NotNull DfaRelationValue dfaRelation) {
     DfaValue dfaLeft = dfaRelation.getLeftOperand();
     DfaValue dfaRight = dfaRelation.getRightOperand();
     if (dfaLeft instanceof DfaUnknownValue || dfaRight instanceof DfaUnknownValue) return true;
@@ -702,7 +704,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
     return applyEquivalenceRelation(dfaRelation, dfaLeft, dfaRight);
   }
 
-  private void updateVarStateOnComparison(DfaVariableValue dfaVar, DfaValue value) {
+  private void updateVarStateOnComparison(@NotNull DfaVariableValue dfaVar, DfaValue value) {
     if (!isUnknownState(dfaVar)) {
       if (value instanceof DfaConstValue && ((DfaConstValue)value).getValue() == null) {
         setVariableState(dfaVar, getVariableState(dfaVar).withNullability(Nullness.NULLABLE));
@@ -713,7 +715,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
     }
   }
 
-  private boolean applyEquivalenceRelation(DfaRelationValue dfaRelation, DfaValue dfaLeft, DfaValue dfaRight) {
+  private boolean applyEquivalenceRelation(@NotNull DfaRelationValue dfaRelation, DfaValue dfaLeft, DfaValue dfaRight) {
     boolean isNegated = dfaRelation.isNonEquality();
     if (!isNegated && !dfaRelation.isEquality()) {
       return true;
@@ -761,7 +763,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
     return true;
   }
 
-  private boolean applyBoxedRelation(DfaVariableValue dfaLeft, DfaValue dfaRight, boolean negated) {
+  private boolean applyBoxedRelation(@NotNull DfaVariableValue dfaLeft, DfaValue dfaRight, boolean negated) {
     if (!TypeConversionUtil.isPrimitiveAndNotNull(dfaLeft.getVariableType())) return true;
 
     DfaBoxedValue.Factory boxedFactory = myFactory.getBoxedFactory();
@@ -770,7 +772,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
     return boxedLeft == null || boxedRight == null || applyRelation(boxedLeft, boxedRight, negated);
   }
 
-  private boolean applyUnboxedRelation(DfaVariableValue dfaLeft, DfaValue dfaRight, boolean negated) {
+  private boolean applyUnboxedRelation(@NotNull DfaVariableValue dfaLeft, DfaValue dfaRight, boolean negated) {
     PsiType type = dfaLeft.getVariableType();
     if (!TypeConversionUtil.isPrimitiveWrapper(type)) {
       return true;
@@ -912,7 +914,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
     myCachedHash = null;
   }
   
-  public DfaVariableState getVariableState(DfaVariableValue dfaVar) {
+  DfaVariableState getVariableState(DfaVariableValue dfaVar) {
     DfaVariableState state = myVariableStates.get(dfaVar);
 
     if (state == null) {
@@ -935,11 +937,13 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
     return state;
   }
 
-  protected Map<DfaVariableValue, DfaVariableState> getVariableStates() {
+  @NotNull
+  Map<DfaVariableValue, DfaVariableState> getVariableStates() {
     return myVariableStates;
   }
 
-  protected DfaVariableState createVariableState(final DfaVariableValue var) {
+  @NotNull
+  protected DfaVariableState createVariableState(@NotNull DfaVariableValue var) {
     return new DfaVariableState(var);
   }
 
@@ -958,7 +962,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
     }
   }
 
-  private boolean shouldMarkUnknown(DfaVariableValue value) {
+  private boolean shouldMarkUnknown(@NotNull DfaVariableValue value) {
     int eqClassIndex = getEqClassIndex(value);
     if (eqClassIndex < 0) return false;
 
@@ -975,6 +979,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
     return false;
   }
 
+  @NotNull
   Set<DfaVariableValue> getChangedVariables() {
     return myVariableStates.keySet();
   }
@@ -999,17 +1004,18 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
     myCachedHash = null;
   }
 
-  public void flushDependencies(DfaVariableValue variable) {
+  void flushDependencies(@NotNull DfaVariableValue variable) {
     for (DfaVariableValue dependent : myFactory.getVarFactory().getAllQualifiedBy(variable)) {
       doFlush(dependent, false);
     }
   }
 
+  @NotNull
   Set<DfaVariableValue> getUnknownVariables() {
     return myUnknownVariables;
   }
 
-  void doFlush(DfaVariableValue varPlain, boolean markUnknown) {
+  void doFlush(@NotNull DfaVariableValue varPlain, boolean markUnknown) {
     DfaVariableValue varNegated = varPlain.getNegatedValue();
 
     final int idPlain = varPlain.getID();
index 4c78c4807069d21eb0fb286f639aa85786e1c828..f6f72dbb32d7912898461b75ef1964dc2d99808d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2013 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.
@@ -155,8 +155,9 @@ public class DfaPsiUtil {
             return false;
           }
 
+          @NotNull
           @Override
-          protected DfaInstructionState[] acceptInstruction(InstructionVisitor visitor, DfaInstructionState instructionState) {
+          protected DfaInstructionState[] acceptInstruction(@NotNull InstructionVisitor visitor, @NotNull DfaInstructionState instructionState) {
             Instruction instruction = instructionState.getInstruction();
             if (isCallExposingNonInitializedFields(instruction) ||
                 instruction instanceof ReturnInstruction && !((ReturnInstruction)instruction).isViaException()) {
index ae54ff7817cb7d02859701fa9a770040be9c0bca..fa6208115eb0b32ff86cc907c77641c08efbe33f 100644 (file)
@@ -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.
@@ -70,7 +70,7 @@ public class DfaUtil {
       @Override
       public Result<Map<PsiElement, ValuableInstructionVisitor.PlaceResult>> compute() {
         final ValuableInstructionVisitor visitor = new ValuableInstructionVisitor();
-        RunnerResult runnerResult = new ValuableDataFlowRunner(codeBlock).analyzeMethod(codeBlock, visitor);
+        RunnerResult runnerResult = new ValuableDataFlowRunner().analyzeMethod(codeBlock, visitor);
         return Result.create(runnerResult == RunnerResult.OK ? visitor.myResults : null, codeBlock);
       }
     });
@@ -242,11 +242,11 @@ public class DfaUtil {
         final ValuableDataFlowRunner.ValuableDfaVariableState curState = (ValuableDataFlowRunner.ValuableDfaVariableState)memState.getVariableState(var);
         final FList<PsiExpression> curValue = curState.myConcatenation;
         final FList<PsiExpression> nextValue;
-        if (type == JavaTokenType.PLUSEQ && !prevValue.isEmpty()) {
+        if (type == JavaTokenType.PLUSEQ && !prevValue.isEmpty() && rightValue != null) {
           nextValue = prevValue.prepend(rightValue);
         }
         else {
-          nextValue = curValue.isEmpty() ? curValue.prepend(rightValue) : curValue;
+          nextValue = curValue.isEmpty() && rightValue != null ? curValue.prepend(rightValue) : curValue;
         }
         memState.setVariableState(var, curState.withExpression(nextValue));
       }
index 43657cd75ded96907b6861b0ad6b015209714b38..80e1f64cac161b3af30b75f7d158df3b05c1bb04 100644 (file)
@@ -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.
@@ -40,18 +40,19 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
-public class DfaVariableState {
-  protected final Set<DfaPsiType> myInstanceofValues;
-  protected final Set<DfaPsiType> myNotInstanceofValues;
-  protected final Nullness myNullability;
+class DfaVariableState {
+  @NotNull final Set<DfaPsiType> myInstanceofValues;
+  @NotNull final Set<DfaPsiType> myNotInstanceofValues;
+  @NotNull final Nullness myNullability;
   private final int myHash;
 
-  public DfaVariableState(@NotNull DfaVariableValue dfaVar) {
+  DfaVariableState(@NotNull DfaVariableValue dfaVar) {
     this(Collections.<DfaPsiType>emptySet(), Collections.<DfaPsiType>emptySet(), dfaVar.getInherentNullability());
   }
 
-  protected DfaVariableState(Set<DfaPsiType> instanceofValues,
-                             Set<DfaPsiType> notInstanceofValues, Nullness nullability) {
+  DfaVariableState(@NotNull Set<DfaPsiType> instanceofValues,
+                   @NotNull Set<DfaPsiType> notInstanceofValues,
+                   @NotNull Nullness nullability) {
     myInstanceofValues = instanceofValues;
     myNotInstanceofValues = notInstanceofValues;
     myNullability = nullability;
@@ -62,7 +63,7 @@ public class DfaVariableState {
     return myNullability == Nullness.NULLABLE;
   }
 
-  private boolean checkInstanceofValue(DfaPsiType dfaType) {
+  private boolean checkInstanceofValue(@NotNull DfaPsiType dfaType) {
     if (myInstanceofValues.contains(dfaType)) return true;
 
     for (DfaPsiType dfaTypeValue : myNotInstanceofValues) {
@@ -77,7 +78,7 @@ public class DfaVariableState {
   }
 
   @Nullable
-  public DfaVariableState withInstanceofValue(DfaTypeValue dfaType) {
+  DfaVariableState withInstanceofValue(@NotNull DfaTypeValue dfaType) {
     if (dfaType.getDfaType().getPsiType() instanceof PsiPrimitiveType) return this;
 
     if (checkInstanceofValue(dfaType.getDfaType())) {
@@ -103,7 +104,7 @@ public class DfaVariableState {
   }
 
   @Nullable
-  public DfaVariableState withNotInstanceofValue(DfaTypeValue dfaType) {
+  DfaVariableState withNotInstanceofValue(@NotNull DfaTypeValue dfaType) {
     if (myNotInstanceofValues.contains(dfaType.getDfaType())) return this;
 
     for (DfaPsiType dfaTypeValue : myInstanceofValues) {
@@ -126,7 +127,8 @@ public class DfaVariableState {
     return createCopy(myInstanceofValues, newNotInstanceof, myNullability);
   }
 
-  DfaVariableState withoutType(DfaPsiType type) {
+  @NotNull
+  DfaVariableState withoutType(@NotNull DfaPsiType type) {
     if (myInstanceofValues.contains(type)) {
       HashSet<DfaPsiType> newInstanceof = ContainerUtil.newHashSet(myInstanceofValues);
       newInstanceof.remove(type);
@@ -154,7 +156,8 @@ public class DfaVariableState {
            myNotInstanceofValues.equals(aState.myNotInstanceofValues);
   }
 
-  protected DfaVariableState createCopy(Set<DfaPsiType> instanceofValues, Set<DfaPsiType> notInstanceofValues, Nullness nullability) {
+  @NotNull
+  protected DfaVariableState createCopy(@NotNull Set<DfaPsiType> instanceofValues, @NotNull Set<DfaPsiType> notInstanceofValues, @NotNull Nullness nullability) {
     return new DfaVariableState(instanceofValues, notInstanceofValues, nullability);
   }
 
@@ -172,7 +175,8 @@ public class DfaVariableState {
     return buf.toString();
   }
 
-  public Nullness getNullability() {
+  @NotNull
+  Nullness getNullability() {
     return myNullability;
   }
 
@@ -180,14 +184,17 @@ public class DfaVariableState {
     return myNullability == Nullness.NOT_NULL;
   }
 
+  @NotNull
   DfaVariableState withNullability(@NotNull Nullness nullness) {
     return myNullability == nullness ? this : createCopy(myInstanceofValues, myNotInstanceofValues, nullness);
   }
 
-  public DfaVariableState withNullable(final boolean nullable) {
+  @NotNull
+  DfaVariableState withNullable(final boolean nullable) {
     return myNullability != Nullness.NOT_NULL ? withNullability(nullable ? Nullness.NULLABLE : Nullness.UNKNOWN) : this;
   }
 
+  @NotNull
   public DfaVariableState withValue(DfaValue value) {
     return this;
   }
index fb866355d0526389fecc3f5d147024d71469f044..e07ed22d6681d5bc0bf8d038a73ff79a5b890b63 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2013 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.
@@ -32,11 +32,11 @@ import java.util.*;
  * @author peter
  */
 class StateMerger {
-  private final Map<DfaMemoryStateImpl, LinkedHashSet<Fact>> myFacts = ContainerUtil.newIdentityHashMap();
+  private final Map<DfaMemoryStateImpl, Set<Fact>> myFacts = ContainerUtil.newIdentityHashMap();
   private final Map<DfaMemoryState, Map<DfaVariableValue, DfaMemoryStateImpl>> myCopyCache = ContainerUtil.newIdentityHashMap();
 
   @Nullable
-  List<DfaMemoryStateImpl> mergeByFacts(List<DfaMemoryStateImpl> states) {
+  List<DfaMemoryStateImpl> mergeByFacts(@NotNull List<DfaMemoryStateImpl> states) {
     MultiMap<Fact, DfaMemoryStateImpl> statesByFact = MultiMap.createLinked();
     for (DfaMemoryStateImpl state : states) {
       ProgressManager.checkCanceled();
@@ -84,8 +84,8 @@ class StateMerger {
   }
 
   @NotNull
-  private MultiMap<Set<Fact>, DfaMemoryStateImpl> mapByUnrelatedFacts(Fact fact,
-                                                                      Collection<DfaMemoryStateImpl> states1) {
+  private MultiMap<Set<Fact>, DfaMemoryStateImpl> mapByUnrelatedFacts(@NotNull Fact fact,
+                                                                      @NotNull Collection<DfaMemoryStateImpl> states1) {
     MultiMap<Set<Fact>, DfaMemoryStateImpl> statesByUnrelatedFacts1 = MultiMap.createLinked();
     for (DfaMemoryStateImpl state : states1) {
       statesByUnrelatedFacts1.putValue(getUnrelatedFacts(fact, state), state);
@@ -93,7 +93,8 @@ class StateMerger {
     return statesByUnrelatedFacts1;
   }
 
-  private LinkedHashSet<Fact> getUnrelatedFacts(final Fact fact, DfaMemoryStateImpl state) {
+  @NotNull
+  private LinkedHashSet<Fact> getUnrelatedFacts(@NotNull final Fact fact, @NotNull DfaMemoryStateImpl state) {
     return new LinkedHashSet<Fact>(ContainerUtil.filter(getFacts(state), new Condition<Fact>() {
       @Override
       public boolean value(Fact another) {
@@ -102,10 +103,10 @@ class StateMerger {
     }));
   }
 
-  private void restoreOtherInequalities(Fact removedFact, Collection<DfaMemoryStateImpl> mergedGroup, DfaMemoryStateImpl state) {
+  private void restoreOtherInequalities(@NotNull Fact removedFact, @NotNull Collection<DfaMemoryStateImpl> mergedGroup, @NotNull DfaMemoryStateImpl state) {
     Set<DfaConstValue> inequalitiesToRestore = null;
     for (DfaMemoryStateImpl member : mergedGroup) {
-      LinkedHashSet<Fact> memberFacts = getFacts(member);
+      Set<Fact> memberFacts = getFacts(member);
       if (memberFacts.contains(removedFact)) {
         Set<DfaConstValue> otherInequalities = getOtherInequalities(removedFact, memberFacts, member);
         if (inequalitiesToRestore == null) {
@@ -123,7 +124,8 @@ class StateMerger {
     }
   }
 
-  private static Set<DfaConstValue> getOtherInequalities(Fact removedFact, LinkedHashSet<Fact> memberFacts, DfaMemoryStateImpl state) {
+  @NotNull
+  private static Set<DfaConstValue> getOtherInequalities(@NotNull Fact removedFact, @NotNull Set<Fact> memberFacts, @NotNull DfaMemoryStateImpl state) {
     Set<DfaConstValue> otherInequalities = ContainerUtil.newLinkedHashSet();
     Set<DfaValue> eqValues = ContainerUtil.newHashSet(state.getEquivalentValues((DfaValue)removedFact.myArg));
     for (Fact candidate : memberFacts) {
@@ -136,7 +138,8 @@ class StateMerger {
     return otherInequalities;
   }
 
-  private static Set<DfaVariableValue> getAllUnknownVariables(Collection<DfaMemoryStateImpl> complementary) {
+  @NotNull
+  private static Set<DfaVariableValue> getAllUnknownVariables(@NotNull Collection<DfaMemoryStateImpl> complementary) {
     final Set<DfaVariableValue> toFlush = ContainerUtil.newLinkedHashSet();
     for (DfaMemoryStateImpl removedState : complementary) {
       toFlush.addAll(removedState.getUnknownVariables());
@@ -144,7 +147,8 @@ class StateMerger {
     return toFlush;
   }
 
-  private static DfaMemoryStateImpl withUnknownVariables(DfaMemoryStateImpl original, Set<DfaVariableValue> toFlush) {
+  @NotNull
+  private static DfaMemoryStateImpl withUnknownVariables(@NotNull DfaMemoryStateImpl original, @NotNull Set<DfaVariableValue> toFlush) {
     DfaMemoryStateImpl copy = original.createCopy();
     for (DfaVariableValue value : toFlush) {
       copy.doFlush(value, true);
@@ -153,7 +157,7 @@ class StateMerger {
   }
 
   @Nullable
-  public List<DfaMemoryStateImpl> mergeByUnknowns(List<DfaMemoryStateImpl> states) {
+  List<DfaMemoryStateImpl> mergeByUnknowns(@NotNull List<DfaMemoryStateImpl> states) {
     MultiMap<Integer, DfaMemoryStateImpl> byHash = new MultiMap<Integer, DfaMemoryStateImpl>();
     for (DfaMemoryStateImpl state : states) {
       ProgressManager.checkCanceled();
@@ -181,7 +185,7 @@ class StateMerger {
   }
   
   @Nullable
-  public List<DfaMemoryStateImpl> mergeByNullability(List<DfaMemoryStateImpl> states) {
+  List<DfaMemoryStateImpl> mergeByNullability(List<DfaMemoryStateImpl> states) {
     MultiMap<Integer, DfaMemoryStateImpl> byHash = new MultiMap<Integer, DfaMemoryStateImpl>();
     for (DfaMemoryStateImpl state : states) {
       ProgressManager.checkCanceled();
@@ -217,7 +221,7 @@ class StateMerger {
     return replacements.getMergeResult();
   }
 
-  private static boolean mergeUnknowns(Replacements replacements, List<DfaMemoryStateImpl> complementary) {
+  private static boolean mergeUnknowns(@NotNull Replacements replacements, @NotNull List<DfaMemoryStateImpl> complementary) {
     if (complementary.size() < 2) return false;
 
     final Set<DfaVariableValue> toFlush = getAllUnknownVariables(complementary);
@@ -231,13 +235,14 @@ class StateMerger {
     });
   }
 
-  private boolean areEquivalentModuloVar(DfaMemoryStateImpl state1, DfaMemoryStateImpl state2, DfaVariableValue var) {
+  private boolean areEquivalentModuloVar(@NotNull DfaMemoryStateImpl state1, @NotNull DfaMemoryStateImpl state2, @NotNull DfaVariableValue var) {
     DfaMemoryStateImpl copy1 = copyWithoutVar(state1, var);
     DfaMemoryStateImpl copy2 = copyWithoutVar(state2, var);
     return copy2.equalsByRelations(copy1) && copy2.equalsByVariableStates(copy1);
   }
 
-  private DfaMemoryStateImpl copyWithoutVar(DfaMemoryStateImpl state, DfaVariableValue var) {
+  @NotNull
+  private DfaMemoryStateImpl copyWithoutVar(@NotNull DfaMemoryStateImpl state, @NotNull DfaVariableValue var) {
     Map<DfaVariableValue, DfaMemoryStateImpl> map = myCopyCache.get(state);
     if (map == null) {
       myCopyCache.put(state, map = ContainerUtil.newIdentityHashMap());
@@ -251,12 +256,13 @@ class StateMerger {
     return copy;
   }
 
-  private static boolean areVarStatesEqualModuloNullability(DfaMemoryStateImpl state1, DfaMemoryStateImpl state2, DfaVariableValue var) {
+  private static boolean areVarStatesEqualModuloNullability(@NotNull DfaMemoryStateImpl state1, @NotNull DfaMemoryStateImpl state2, @NotNull DfaVariableValue var) {
     return state1.getVariableState(var).withNullability(Nullness.UNKNOWN).equals(state2.getVariableState(var).withNullability(Nullness.UNKNOWN));
   }
 
-  private LinkedHashSet<Fact> getFacts(DfaMemoryStateImpl state) {
-    LinkedHashSet<Fact> result = myFacts.get(state);
+  @NotNull
+  private Set<Fact> getFacts(@NotNull DfaMemoryStateImpl state) {
+    Set<Fact> result = myFacts.get(state);
     if (result != null) {
       return result;
     }
@@ -317,12 +323,13 @@ class StateMerger {
   private enum FactType { equality, instanceOf }
 
   private static class Fact {
-    final FactType myType;
-    final DfaVariableValue myVar;
-    final boolean myPositive;
-    final Object myArg; // DfaValue for equality fact, DfaPsiType for instanceOf fact
+    @NotNull final FactType myType;
+    @NotNull private final DfaVariableValue myVar;
+    private final boolean myPositive;
+    @NotNull
+    private final Object myArg; // DfaValue for equality fact, DfaPsiType for instanceOf fact
 
-    private Fact(FactType type, DfaVariableValue var, boolean positive, Object arg) {
+    private Fact(@NotNull FactType type, @NotNull DfaVariableValue var, boolean positive, @NotNull Object arg) {
       myType = type;
       myVar = var;
       myPositive = positive;
@@ -358,18 +365,20 @@ class StateMerger {
       return myVar + " " + (myPositive ? "" : "!") + myType + " " + myArg;
     }
 
-    static Fact createEqualityFact(DfaVariableValue var, DfaValue val, boolean equal) {
+    @NotNull
+    private static Fact createEqualityFact(@NotNull DfaVariableValue var, @NotNull DfaValue val, boolean equal) {
       if (val instanceof DfaVariableValue && val.getID() < var.getID()) {
         return new Fact(FactType.equality, (DfaVariableValue)val, equal, var);
       }
       return new Fact(FactType.equality, var, equal, val);
     }
 
-    Fact getPositiveCounterpart() {
+    @NotNull
+    private Fact getPositiveCounterpart() {
       return new Fact(myType, myVar, true, myArg);
     }
 
-    boolean invalidatesFact(Fact another) {
+    boolean invalidatesFact(@NotNull Fact another) {
       if (another.myType != myType) return false;
       if (myType == FactType.equality) {
         return aboutSame(myVar, another.myVar) || aboutSame(myVar, another.myArg);
@@ -377,18 +386,18 @@ class StateMerger {
       return aboutSame(myVar, another.myVar) && aboutSame(myArg, another.myArg);
     }
     
-    static boolean aboutSame(Object v1, Object v2) {
+    private static boolean aboutSame(Object v1, Object v2) {
       return normalize(v1) == normalize(v2);
     }
 
-    static Object normalize(Object value) {
+    private static Object normalize(Object value) {
       if (value instanceof DfaVariableValue && ((DfaVariableValue)value).isNegated()) {
         return ((DfaVariableValue)value).createNegated();
       }
       return value;
     }
 
-    void removeFromState(DfaMemoryStateImpl state) {
+    void removeFromState(@NotNull DfaMemoryStateImpl state) {
       DfaVariableState varState = state.getVariableState(myVar);
       if (myType == FactType.equality) {
         state.flushVariable(myVar);
@@ -400,18 +409,18 @@ class StateMerger {
   }
 
   private static class Replacements {
-    private final List<DfaMemoryStateImpl> myAllStates;
+    @NotNull private final List<DfaMemoryStateImpl> myAllStates;
     private final Set<DfaMemoryStateImpl> myRemovedStates = ContainerUtil.newIdentityTroveSet();
     private final List<DfaMemoryStateImpl> myMerged = ContainerUtil.newArrayList();
 
-    Replacements(List<DfaMemoryStateImpl> allStates) {
+    private Replacements(@NotNull List<DfaMemoryStateImpl> allStates) {
       myAllStates = allStates;
     }
 
-    boolean hasMerges() { return !myMerged.isEmpty(); }
+    private boolean hasMerges() { return !myMerged.isEmpty(); }
 
     @Nullable
-    List<DfaMemoryStateImpl> getMergeResult() {
+    private List<DfaMemoryStateImpl> getMergeResult() {
       if (hasMerges()) {
         List<DfaMemoryStateImpl> result = ContainerUtil.newArrayList(myMerged);
         for (DfaMemoryStateImpl state : myAllStates) {
@@ -424,15 +433,15 @@ class StateMerger {
       return null;
     }
 
-    boolean stripAndMerge(Collection<DfaMemoryStateImpl> group,
-                               Function<DfaMemoryStateImpl, DfaMemoryStateImpl> stripper) {
+    private boolean stripAndMerge(@NotNull Collection<DfaMemoryStateImpl> group,
+                                  @NotNull Function<DfaMemoryStateImpl, DfaMemoryStateImpl> stripper) {
       if (group.size() <= 1) return false;
 
-      boolean hasMerges = false;
       MultiMap<DfaMemoryStateImpl, DfaMemoryStateImpl> strippedToOriginals = MultiMap.create();
       for (DfaMemoryStateImpl original : group) {
         strippedToOriginals.putValue(stripper.fun(original), original);
       }
+      boolean hasMerges = false;
       for (Map.Entry<DfaMemoryStateImpl, Collection<DfaMemoryStateImpl>> entry : strippedToOriginals.entrySet()) {
         Collection<DfaMemoryStateImpl> merged = entry.getValue();
         if (merged.size() > 1) {
index bf78faf17b66dc1edef835c9cbd047c522435102..51daae3aa476f610fac536b9a24411b56b3a29ed 100644 (file)
@@ -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.
@@ -20,7 +20,6 @@ import com.intellij.codeInspection.dataFlow.value.DfaPsiType;
 import com.intellij.codeInspection.dataFlow.value.DfaValue;
 import com.intellij.codeInspection.dataFlow.value.DfaValueFactory;
 import com.intellij.codeInspection.dataFlow.value.DfaVariableValue;
-import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiExpression;
 import com.intellij.util.containers.FList;
 import org.jetbrains.annotations.NotNull;
@@ -31,33 +30,31 @@ import java.util.Set;
 /**
  * @author Gregory.Shrago
  */
-public class ValuableDataFlowRunner extends DataFlowRunner {
-
-  protected ValuableDataFlowRunner(PsiElement block) {
-    super();
-  }
-
+class ValuableDataFlowRunner extends DataFlowRunner {
+  @NotNull
   @Override
   protected DfaMemoryState createMemoryState() {
     return new MyDfaMemoryState(getFactory());
   }
 
   static class MyDfaMemoryState extends DfaMemoryStateImpl {
-    private MyDfaMemoryState(final DfaValueFactory factory) {
+    private MyDfaMemoryState(@NotNull DfaValueFactory factory) {
       super(factory);
     }
 
-    MyDfaMemoryState(DfaMemoryStateImpl toCopy) {
+    private MyDfaMemoryState(@NotNull DfaMemoryStateImpl toCopy) {
       super(toCopy);
     }
 
+    @NotNull
     @Override
     public DfaMemoryStateImpl createCopy() {
       return new MyDfaMemoryState(this);
     }
 
+    @NotNull
     @Override
-    protected DfaVariableState createVariableState(DfaVariableValue var) {
+    protected DfaVariableState createVariableState(@NotNull DfaVariableValue var) {
       return new ValuableDfaVariableState(var);
     }
 
@@ -68,35 +65,38 @@ public class ValuableDataFlowRunner extends DataFlowRunner {
   }
 
   static class ValuableDfaVariableState extends DfaVariableState {
-    final DfaValue myValue;
+    private final DfaValue myValue;
     @NotNull final FList<PsiExpression> myConcatenation;
 
-    private ValuableDfaVariableState(final DfaVariableValue psiVariable) {
+    private ValuableDfaVariableState(@NotNull DfaVariableValue psiVariable) {
       super(psiVariable);
       myValue = null;
       myConcatenation = FList.emptyList();
     }
 
     private ValuableDfaVariableState(Set<DfaPsiType> instanceofValues,
-                             Set<DfaPsiType> notInstanceofValues,
-                             Nullness nullability, DfaValue value, @NotNull FList<PsiExpression> concatenation) {
+                                     Set<DfaPsiType> notInstanceofValues,
+                                     Nullness nullability, DfaValue value,
+                                     @NotNull FList<PsiExpression> concatenation) {
       super(instanceofValues, notInstanceofValues, nullability);
       myValue = value;
       myConcatenation = concatenation;
     }
 
+    @NotNull
     @Override
-    protected DfaVariableState createCopy(Set<DfaPsiType> instanceofValues, Set<DfaPsiType> notInstanceofValues, Nullness nullability) {
+    protected DfaVariableState createCopy(@NotNull Set<DfaPsiType> instanceofValues, @NotNull Set<DfaPsiType> notInstanceofValues, @NotNull Nullness nullability) {
       return new ValuableDfaVariableState(instanceofValues, notInstanceofValues, nullability, myValue, myConcatenation);
     }
 
+    @NotNull
     @Override
     public DfaVariableState withValue(@Nullable final DfaValue value) {
       if (value == myValue) return this;
       return new ValuableDfaVariableState(myInstanceofValues, myNotInstanceofValues, myNullability, value, myConcatenation);
     }
 
-    public ValuableDfaVariableState withExpression(@NotNull final FList<PsiExpression> concatenation) {
+    ValuableDfaVariableState withExpression(@NotNull final FList<PsiExpression> concatenation) {
       if (concatenation == myConcatenation) return this;
       return new ValuableDfaVariableState(myInstanceofValues, myNotInstanceofValues, myNullability, myValue, concatenation);
     }
index 7037613ff003c892242801f397b32e7904e04ff7..b86085c4bb2dabb7f371d7163c187a4cf757715c 100644 (file)
@@ -35,19 +35,21 @@ import java.util.Map;
 public class DfaTypeValue extends DfaValue {
   public static class Factory {
     private final Map<DfaPsiType,ArrayList<DfaTypeValue>> myCache = ContainerUtil.newHashMap();
+    @NotNull
     private final DfaValueFactory myFactory;
 
-    Factory(DfaValueFactory factory) {
+    Factory(@NotNull DfaValueFactory factory) {
       myFactory = factory;
     }
 
     @NotNull
-    public DfaTypeValue createTypeValue(@NotNull DfaPsiType type, @NotNull Nullness nullness) {
+    DfaTypeValue createTypeValue(@NotNull DfaPsiType type, @NotNull Nullness nullness) {
       ArrayList<DfaTypeValue> conditions = myCache.get(type);
       if (conditions == null) {
         conditions = new ArrayList<DfaTypeValue>();
         myCache.put(type, conditions);
-      } else {
+      }
+      else {
         for (DfaTypeValue aType : conditions) {
           if (aType.myNullness == nullness) return aType;
         }
@@ -60,15 +62,18 @@ public class DfaTypeValue extends DfaValue {
 
   }
 
+  @NotNull
   private final DfaPsiType myType;
+  @NotNull
   private final Nullness myNullness;
 
-  private DfaTypeValue(DfaPsiType type, Nullness nullness, DfaValueFactory factory) {
+  private DfaTypeValue(@NotNull DfaPsiType type, @NotNull Nullness nullness, @NotNull DfaValueFactory factory) {
     super(factory);
     myType = type;
     myNullness = nullness;
   }
 
+  @NotNull
   public DfaPsiType getDfaType() {
     return myType;
   }
@@ -81,6 +86,7 @@ public class DfaTypeValue extends DfaValue {
     return myNullness == Nullness.NOT_NULL;
   }
 
+  @NotNull
   public Nullness getNullness() {
     return myNullness;
   }
index 4a260d7c827b1efc6091e9baa075c4fe35da479c..9a20ae691695aa30916e72377271f780b84e375b 100644 (file)
@@ -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.
@@ -64,7 +64,8 @@ public class DfaValueFactory {
     return myUnknownMembersAreNullable;
   }
 
-  public DfaValue createTypeValue(@Nullable PsiType type, Nullness nullability) {
+  @NotNull
+  public DfaValue createTypeValue(@Nullable PsiType type, @NotNull Nullness nullability) {
     type = TypeConversionUtil.erasure(type);
     if (type == null) return DfaUnknownValue.getInstance();
     return getTypeFactory().createTypeValue(internType(type), nullability);
index f8f6d16aed13fa91b8744a2d790234ad30043c0a..ae3107236e11bbed2b7bc0f0dc11e83e297db74e 100644 (file)
@@ -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.
@@ -81,10 +81,10 @@ public class DfaVariableValue extends DfaValue {
       return result;
     }
 
-    public List<DfaVariableValue> getAllQualifiedBy(DfaVariableValue value) {
+    @NotNull
+    public List<DfaVariableValue> getAllQualifiedBy(@NotNull DfaVariableValue value) {
       return value.myDependents;
     }
-
   }
 
   private final PsiModifierListOwner myVariable;
@@ -159,6 +159,7 @@ public class DfaVariableValue extends DfaValue {
     return myQualifier;
   }
 
+  @NotNull
   public Nullness getInherentNullability() {
     if (myInherentNullability != null) {
       return myInherentNullability;
@@ -167,6 +168,7 @@ public class DfaVariableValue extends DfaValue {
     return myInherentNullability = calcInherentNullability();
   }
 
+  @NotNull
   private Nullness calcInherentNullability() {
     PsiModifierListOwner var = getPsiVariable();
     Nullness nullability = DfaPsiUtil.getElementNullability(getVariableType(), var);
index 71016e8d6795ff12ed3181b15655e692792bc7b6..27be172ae58a0723b55095c2edc5fe23c2580ee3 100644 (file)
@@ -25,6 +25,8 @@ import com.intellij.codeInsight.quickfix.ChangeVariableTypeQuickFixProvider;
 import com.intellij.codeInspection.*;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.extensions.Extensions;
+import com.intellij.openapi.projectRoots.JavaSdkVersion;
+import com.intellij.openapi.projectRoots.JavaVersionService;
 import com.intellij.openapi.util.Pass;
 import com.intellij.openapi.util.WriteExternalException;
 import com.intellij.pom.java.LanguageLevel;
@@ -229,7 +231,7 @@ public class UncheckedWarningLocalInspectionBase extends BaseJavaBatchLocalInspe
       super.visitMethodReferenceExpression(expression);
       if (IGNORE_UNCHECKED_CALL) return;
       final JavaResolveResult result = expression.advancedResolve(false);
-      final String description = getUncheckedCallDescription(result);
+      final String description = getUncheckedCallDescription(expression, result);
       if (description != null) {
         final PsiElement referenceNameElement = expression.getReferenceNameElement();
         registerProblem(description, expression, referenceNameElement != null ? referenceNameElement : expression, myGenerifyFixes);
@@ -240,7 +242,7 @@ public class UncheckedWarningLocalInspectionBase extends BaseJavaBatchLocalInspe
     public void visitCallExpression(PsiCallExpression callExpression) {
       super.visitCallExpression(callExpression);
       final JavaResolveResult result = callExpression.resolveMethodGenerics();
-      final String description = getUncheckedCallDescription(result);
+      final String description = getUncheckedCallDescription(callExpression, result);
       if (description != null) {
         if (IGNORE_UNCHECKED_CALL) return;
         final PsiExpression element = callExpression instanceof PsiMethodCallExpression
@@ -421,12 +423,27 @@ public class UncheckedWarningLocalInspectionBase extends BaseJavaBatchLocalInspe
 
 
     @Nullable
-    private String getUncheckedCallDescription(JavaResolveResult resolveResult) {
+    private String getUncheckedCallDescription(PsiElement place, JavaResolveResult resolveResult) {
       final PsiElement element = resolveResult.getElement();
       if (!(element instanceof PsiMethod)) return null;
       final PsiMethod method = (PsiMethod)element;
       final PsiSubstitutor substitutor = resolveResult.getSubstitutor();
-      if (!PsiUtil.isRawSubstitutor(method, substitutor)) return null;
+      if (!PsiUtil.isRawSubstitutor(method, substitutor)) {
+        if (JavaVersionService.getInstance().isAtLeast(place, JavaSdkVersion.JDK_1_8)) {
+          for (PsiTypeParameter parameter : PsiUtil.typeParametersIterable(method)) {
+            final PsiClassType[] extendsListTypes = parameter.getExtendsListTypes();
+            if (extendsListTypes.length > 0) {
+              final PsiType subst = substitutor.substitute(parameter);
+              for (PsiClassType classType : extendsListTypes) {
+                if (JavaGenericsUtil.isRawToGeneric(substitutor.substitute(classType), subst)) {
+                  return JavaErrorMessages.message("generics.unchecked.call", JavaHighlightUtil.formatMethod(method));
+                }
+              }
+            }
+          }
+        }
+        return null;
+      }
       final PsiParameter[] parameters = method.getParameterList().getParameters();
       for (final PsiParameter parameter : parameters) {
         final PsiType parameterType = parameter.getType();
index e51101c98460b00483267fb05e3e4dd26b44d1e2..a8314ed47117464be88a9a9e934f1da3e95b3b8e 100644 (file)
@@ -123,7 +123,7 @@ public class UnnecessaryModuleDependencyInspection extends GlobalInspectionTool
       final String allContainsMessage = InspectionsBundle.message("unnecessary.module.dependency.problem.descriptor", module.getName(), dependency.getName());
       return manager.createProblemDescriptor(allContainsMessage, new RemoveModuleDependencyFix(module, dependency));
     } else {
-      String message = InspectionsBundle.message("suspected.module.dependency.problem.descriptor", module.getName(), dependency.getName(), scope.getDisplayName(), dependency.getName());
+      String message = InspectionsBundle.message("suspected.module.dependency.problem.descriptor", module.getName(), dependency.getName(), scope.getDisplayName());
       return manager.createProblemDescriptor(message);
     }
   }
index e5660c288fa975ded54ac4d586e09e5fd551e0fc..4d86f34734ea611a042facb3444dd8e01aae1e9d 100644 (file)
@@ -22,6 +22,7 @@ import com.intellij.psi.*;
 import com.intellij.psi.search.LocalSearchScope;
 import com.intellij.psi.search.SearchScope;
 import com.intellij.psi.search.searches.ClassInheritorsSearch;
+import com.intellij.psi.search.searches.FunctionalExpressionSearch;
 import com.intellij.psi.util.*;
 import com.intellij.util.Processor;
 import com.intellij.util.ThreeState;
@@ -310,7 +311,7 @@ public class JavaTargetElementEvaluator extends TargetElementEvaluatorEx2 implem
   
   @Override
   @Nullable
-  public SearchScope getSearchScope(Editor editor, @NotNull PsiElement element) {
+  public SearchScope getSearchScope(Editor editor, @NotNull final PsiElement element) {
     final PsiReferenceExpression referenceExpression = editor != null ? findReferenceExpression(editor) : null;
     if (referenceExpression != null && element instanceof PsiMethod) {
       final PsiClass[] memberClass = getMemberClass(referenceExpression, element);
@@ -326,9 +327,13 @@ public class JavaTargetElementEvaluator extends TargetElementEvaluatorEx2 implem
             for (PsiClass psiClass : classesToSearch) {
               supers.addAll(InheritanceUtil.getSuperClasses(psiClass));
             }
-            classesToSearch.addAll(supers);
 
-            return new Result<SearchScope>(new LocalSearchScope(PsiUtilCore.toPsiElementArray(classesToSearch)), PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
+            final List<PsiElement> elements = new ArrayList<PsiElement>();
+            elements.addAll(classesToSearch);
+            elements.addAll(supers);
+            elements.addAll(FunctionalExpressionSearch.search(memberClass[0]).findAll());
+
+            return new Result<SearchScope>(new LocalSearchScope(PsiUtilCore.toPsiElementArray(elements)), PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
           }
         });
       }
index 1c69fae0762596808d368df0ae20d9028389a13e..d33afa27c24586237fb1afe298d2be2c97d3ef05 100644 (file)
@@ -17,19 +17,23 @@ package com.intellij.codeInsight.daemon.impl.quickfix;
 
 import com.intellij.codeInsight.CodeInsightBundle;
 import com.intellij.codeInsight.FileModificationService;
-import com.intellij.codeInsight.completion.*;
+import com.intellij.codeInsight.completion.JavaInheritorsGetter;
+import com.intellij.codeInsight.completion.PrefixMatcher;
+import com.intellij.codeInsight.completion.StatisticsWeigher;
 import com.intellij.codeInsight.intention.IntentionAction;
-import com.intellij.codeInsight.lookup.*;
+import com.intellij.codeInsight.lookup.ExpressionLookupItem;
+import com.intellij.codeInsight.lookup.LookupElement;
+import com.intellij.codeInsight.lookup.PsiTypeLookupItem;
 import com.intellij.codeInsight.template.*;
 import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.editor.CaretModel;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.project.Project;
 import com.intellij.psi.*;
-import com.intellij.psi.util.InheritanceUtil;
+import com.intellij.psi.filters.getters.JavaMembersGetter;
 import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.psi.util.PsiTypesUtil;
 import com.intellij.psi.util.PsiUtil;
-import com.intellij.refactoring.util.RefactoringUtil;
 import com.intellij.util.Consumer;
 import com.intellij.util.Function;
 import com.intellij.util.IncorrectOperationException;
@@ -38,11 +42,13 @@ import com.intellij.util.containers.ContainerUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 
-import static com.intellij.util.containers.ContainerUtil.*;
+import static com.intellij.util.containers.ContainerUtil.map;
+import static com.intellij.util.containers.ContainerUtil.sorted;
 
 public class AddVariableInitializerFix implements IntentionAction {
   private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.quickfix.AddReturnFix");
@@ -76,11 +82,10 @@ public class AddVariableInitializerFix implements IntentionAction {
   @Override
   public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
     if (!FileModificationService.getInstance().prepareFileForWrite(myVariable.getContainingFile())) return;
-
     final LookupElement[] suggestedInitializers = suggestInitializer(myVariable);
     LOG.assertTrue(suggestedInitializers.length > 0);
     LOG.assertTrue(suggestedInitializers[0] instanceof ExpressionLookupItem);
-    final PsiExpression initializer = (PsiExpression) suggestedInitializers[0].getObject();
+    final PsiExpression initializer = (PsiExpression)suggestedInitializers[0].getObject();
     if (myVariable instanceof PsiLocalVariable) {
       ((PsiLocalVariable)myVariable).setInitializer(initializer);
     }
@@ -88,7 +93,7 @@ public class AddVariableInitializerFix implements IntentionAction {
       ((PsiField)myVariable).setInitializer(initializer);
     }
     else {
-      LOG.error("Unknown variable type: "+myVariable);
+      LOG.error("Unknown variable type: " + myVariable);
     }
     runAssignmentTemplate(Collections.singletonList(myVariable.getInitializer()), suggestedInitializers, editor);
   }
@@ -130,80 +135,20 @@ public class AddVariableInitializerFix implements IntentionAction {
   public static LookupElement[] suggestInitializer(final PsiVariable variable) {
     PsiType type = variable.getType();
     final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(variable.getProject());
+
+    final List<LookupElement> result = new SmartList<LookupElement>();
+    final String defaultValue = PsiTypesUtil.getDefaultValueOfType(type);
+    final ExpressionLookupItem defaultExpression = new ExpressionLookupItem(elementFactory.createExpressionFromText(defaultValue, variable));
+    result.add(defaultExpression);
     if (type instanceof PsiClassType) {
       final PsiClass aClass = PsiTypesUtil.getPsiClass(type);
-      if (aClass != null) {
-        final LookupElement nullLookupItem = new ExpressionLookupItem(elementFactory.createExpressionFromText(PsiKeyword.NULL, variable));
-        if (InheritanceUtil.isInheritor(aClass, CommonClassNames.JAVA_LANG_ITERABLE) ||
-            InheritanceUtil.isInheritor(aClass, CommonClassNames.JAVA_UTIL_MAP)) {
-          final List<PsiType> suggestedTypes = new SmartList<PsiType>();
-          JavaInheritorsGetter.processInheritors(variable.getContainingFile(), variable, Collections.singleton((PsiClassType) type), PrefixMatcher.ALWAYS_TRUE, new Consumer<PsiType>() {
-            @Override
-            public void consume(PsiType type) {
-              LOG.assertTrue(type instanceof PsiClassType);
-              final PsiClass psiClass = PsiTypesUtil.getPsiClass(type);
-              if (psiClass != null &&
-                  !psiClass.isInterface() &&
-                  !psiClass.hasModifierProperty(PsiModifier.ABSTRACT) &&
-                  psiClass.hasModifierProperty(PsiModifier.PUBLIC) &&
-                  PsiUtil.hasDefaultConstructor(psiClass)) {
-                suggestedTypes.add(type);
-              }
-            }
-          });
-
-          List<LookupElement> sortedLookups = map(sorted(map(suggestedTypes, new Function<PsiType, LookupElement>() {
-            @Override
-            public LookupElement fun(PsiType type) {
-              return PsiTypeLookupItem.createLookupItem(type, variable);
-            }
-          }), new Comparator<LookupElement>() {
-            @Override
-            public int compare(LookupElement o1, LookupElement o2) {
-              final int count1 = StatisticsWeigher.getBaseStatisticsInfo(o1, null).getUseCount();
-              final int count2 = StatisticsWeigher.getBaseStatisticsInfo(o2, null).getUseCount();
-              return count2 - count1;
-            }
-          }), new Function<LookupElement, LookupElement>() {
-            @Override
-            public LookupElement fun(LookupElement element) {
-              final LookupElementDecorator<LookupElement> constructorLookupElement =
-                LookupElementDecorator.withInsertHandler(element, ConstructorInsertHandler.BASIC_INSTANCE);
-              return new LookupElementDecorator<LookupElement>(constructorLookupElement) {
-                @Override
-                public void renderElement(LookupElementPresentation presentation) {
-                  super.renderElement(presentation);
-                  presentation.setTailText("");
-                  presentation.setItemText(PsiKeyword.NEW + " " + presentation.getItemText() + "()");
-                }
-
-                @Override
-                public void handleInsert(InsertionContext context) {
-                  super.handleInsert(context);
-                  context.getDocument().insertString(context.getStartOffset(), PsiKeyword.NEW + " ");
-                }
-              };
-            }
-          });
-          LookupElement[] result = new LookupElement[sortedLookups.size() + 1];
-          result[0] = nullLookupItem;
-          for (int i = 0; i < sortedLookups.size(); i++) {
-            LookupElement lookup = sortedLookups.get(i);
-            result[i + 1] = lookup;
-          }
-          return result;
-        } else {
-          if (PsiUtil.hasDefaultConstructor(aClass)) {
-            final PsiExpression newExpression = elementFactory
-              .createExpressionFromText(PsiKeyword.NEW + " " + type.getCanonicalText(false) + "()", variable);
-            return new LookupElement[]{nullLookupItem, new ExpressionLookupItem(newExpression)};
-          }
-        }
+      if (aClass != null && PsiUtil.hasDefaultConstructor(aClass)) {
+        final String expressionText = PsiKeyword.NEW + " " + type.getCanonicalText(false) + "()";
+        ExpressionLookupItem newExpression = new ExpressionLookupItem(elementFactory.createExpressionFromText(expressionText, variable));
+        result.add(newExpression);
       }
     }
-    final String defaultValue = PsiTypesUtil.getDefaultValueOfType(type);
-    final PsiExpression expression = elementFactory.createExpressionFromText(defaultValue, variable);
-    return new LookupElement[] {new ExpressionLookupItem(expression)};
+    return result.toArray(new LookupElement[result.size()]);
   }
 
   @Override
index 5267d1428ea2b5f81210443cea5075b3bccd2557..2f0c016d0f75f9efb8d57141f049b50100d29a33 100644 (file)
@@ -44,6 +44,8 @@ import com.intellij.util.ArrayUtilRt;
 import com.intellij.util.IncorrectOperationException;
 import com.intellij.util.ObjectUtils;
 import com.intellij.util.Processor;
+import com.intellij.util.containers.LinkedMultiMap;
+import com.intellij.util.containers.MultiMap;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -164,25 +166,28 @@ public class StaticImportMethodFix implements IntentionAction {
     final List<PsiMethod> applicableList = new ArrayList<PsiMethod>();
     final PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(element.getProject()).getResolveHelper();
 
-    final Map<PsiClass, PsiMethod> deprecated = new LinkedHashMap<PsiClass, PsiMethod>();
-    final Map<PsiClass, PsiMethod> suggestions = new LinkedHashMap<PsiClass, PsiMethod>();
+    final MultiMap<PsiClass, PsiMethod> deprecated = new LinkedMultiMap<PsiClass, PsiMethod>();
+    final MultiMap<PsiClass, PsiMethod> suggestions = new LinkedMultiMap<PsiClass, PsiMethod>();
     class RegisterMethodsProcessor {
-      private void registerMethod(PsiClass containingClass, PsiMethod method) {
+      private void registerMethod(PsiClass containingClass, Collection<PsiMethod> methods) {
         final Boolean alreadyMentioned = possibleClasses.get(containingClass);
         if (alreadyMentioned == Boolean.TRUE) return;
         if (alreadyMentioned == null) {
-          list.add(method);
+          list.addAll(methods);
           possibleClasses.put(containingClass, false);
         }
-        PsiSubstitutor substitutorForMethod = resolveHelper
-          .inferTypeArguments(method.getTypeParameters(), method.getParameterList().getParameters(),
-                              argumentList.getExpressions(),
-                              PsiSubstitutor.EMPTY, element.getParent(), DefaultParameterTypeInferencePolicy.INSTANCE);
-        if (PsiUtil.isApplicable(method, substitutorForMethod, argumentList)) {
-          final PsiType returnType = substitutorForMethod.substitute(method.getReturnType());
-          if (expectedType == null || returnType == null || TypeConversionUtil.isAssignable(expectedType, returnType)) {
-            applicableList.add(method);
-            possibleClasses.put(containingClass, true);
+        for (PsiMethod method : methods) {
+          PsiSubstitutor substitutorForMethod = resolveHelper
+            .inferTypeArguments(method.getTypeParameters(), method.getParameterList().getParameters(),
+                                argumentList.getExpressions(),
+                                PsiSubstitutor.EMPTY, element.getParent(), DefaultParameterTypeInferencePolicy.INSTANCE);
+          if (PsiUtil.isApplicable(method, substitutorForMethod, argumentList)) {
+            final PsiType returnType = substitutorForMethod.substitute(method.getReturnType());
+            if (expectedType == null || returnType == null || TypeConversionUtil.isAssignable(expectedType, returnType)) {
+              applicableList.add(method);
+              possibleClasses.put(containingClass, true);
+              break;
+            }
           }
         }
       }
@@ -202,10 +207,10 @@ public class StaticImportMethodFix implements IntentionAction {
             && !((PsiJavaFile)file).getPackageName().isEmpty()
             && PsiUtil.isAccessible(file.getProject(), method, element, containingClass)) {
           if (isEffectivelyDeprecated(method)) {
-            deprecated.put(containingClass, method);
+            deprecated.putValue(containingClass, method);
             return processCondition();
           }
-          suggestions.put(containingClass, method);
+          suggestions.putValue(containingClass, method);
         }
         return processCondition();
       }
@@ -229,11 +234,11 @@ public class StaticImportMethodFix implements IntentionAction {
       }
     });
 
-    for (Map.Entry<PsiClass, PsiMethod> methodEntry : suggestions.entrySet()) {
+    for (Map.Entry<PsiClass, Collection<PsiMethod>> methodEntry : suggestions.entrySet()) {
       registrar.registerMethod(methodEntry.getKey(), methodEntry.getValue());
     }
     
-    for (Map.Entry<PsiClass, PsiMethod> deprecatedMethod : deprecated.entrySet()) {
+    for (Map.Entry<PsiClass, Collection<PsiMethod>> deprecatedMethod : deprecated.entrySet()) {
       registrar.registerMethod(deprecatedMethod.getKey(), deprecatedMethod.getValue());
     }
 
index 73623205b438bc9640d917ac1c2259e15e760871..24fd28be4c8d4f5695f4f7e68f836f1dbffbcffa 100644 (file)
@@ -46,7 +46,10 @@ import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
 
 public class RenameJavaVariableProcessor extends RenameJavaMemberProcessor {
   private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.rename.RenameJavaVariableProcessor");
@@ -147,7 +150,7 @@ public class RenameJavaVariableProcessor extends RenameJavaMemberProcessor {
     final JavaCodeStyleManager manager = JavaCodeStyleManager.getInstance(project);
 
     final String propertyName = PropertyUtil.suggestPropertyName(field, field.getName());
-    String newPropertyName = PropertyUtil.suggestPropertyName(field, newName);
+    final String newPropertyName = PropertyUtil.suggestPropertyName(field, newName);
 
     boolean isStatic = field.hasModifierProperty(PsiModifier.STATIC);
 
@@ -158,9 +161,7 @@ public class RenameJavaVariableProcessor extends RenameJavaMemberProcessor {
     boolean shouldRenameSetterParameter = false;
 
     if (setter != null) {
-      String parameterName = manager.propertyNameToVariableName(propertyName, VariableKind.PARAMETER);
-      PsiParameter setterParameter = setter.getParameterList().getParameters()[0];
-      shouldRenameSetterParameter = parameterName.equals(setterParameter.getName());
+      shouldRenameSetterParameter = shouldRenameSetterParameter(manager, propertyName, setter);
     }
 
     if (getters != null) {
@@ -224,18 +225,21 @@ public class RenameJavaVariableProcessor extends RenameJavaMemberProcessor {
         if (newGetterName == null) {
           newGetterName = PropertyUtil.suggestGetterName(newPropertyName, field.getType(), getter.getName());
         }
-        addOverriddenAndImplemented(getter, newGetterName, allRenames);
+        addOverriddenAndImplemented(getter, newGetterName, null, propertyName, manager, allRenames);
       }
     }
 
     if (setter != null) {
-      addOverriddenAndImplemented(setter, newSetterName, allRenames);
+      addOverriddenAndImplemented(setter, newSetterName, shouldRenameSetterParameter ? newPropertyName : null, propertyName, manager, allRenames);
     }
+  }
 
-    if (shouldRenameSetterParameter) {
-      PsiParameter parameter = setter.getParameterList().getParameters()[0];
-      allRenames.put(parameter, manager.propertyNameToVariableName(newPropertyName, VariableKind.PARAMETER));
-    }
+  private static boolean shouldRenameSetterParameter(JavaCodeStyleManager manager, String propertyName, PsiMethod setter) {
+    boolean shouldRenameSetterParameter;
+    String parameterName = manager.propertyNameToVariableName(propertyName, VariableKind.PARAMETER);
+    PsiParameter setterParameter = setter.getParameterList().getParameters()[0];
+    shouldRenameSetterParameter = parameterName.equals(setterParameter.getName());
+    return shouldRenameSetterParameter;
   }
 
   private static boolean askToRenameAccesors(PsiMethod getter, PsiMethod setter, String newName, final Project project) {
@@ -244,8 +248,13 @@ public class RenameJavaVariableProcessor extends RenameJavaMemberProcessor {
     return Messages.showYesNoDialog(project, text, RefactoringBundle.message("rename.title"), Messages.getQuestionIcon()) != Messages.YES;
   }
 
-  private static void addOverriddenAndImplemented(PsiMethod methodPrototype, final String newName, final Map<PsiElement, String> allRenames) {
-    allRenames.put(methodPrototype, newName);
+  private static void addOverriddenAndImplemented(@NotNull final PsiMethod methodPrototype,
+                                                  @NotNull final String newName,
+                                                  @Nullable final String newPropertyName,
+                                                  @NotNull final String oldParameterName,
+                                                  @NotNull final JavaCodeStyleManager manager,
+                                                  @NotNull final Map<PsiElement, String> allRenames) {
+    addGetterOrSetterWithParameter(methodPrototype, newName, newPropertyName, oldParameterName, manager, allRenames);
     PsiMethod[] methods = methodPrototype.findDeepestSuperMethods();
     if (methods.length == 0) {
       methods = new PsiMethod[] {methodPrototype};
@@ -254,11 +263,30 @@ public class RenameJavaVariableProcessor extends RenameJavaMemberProcessor {
       OverridingMethodsSearch.search(method).forEach(new Processor<PsiMethod>() {
         public boolean process(PsiMethod psiMethod) {
           RenameProcessor.assertNonCompileElement(psiMethod);
-          allRenames.put(psiMethod, newName);
+          addGetterOrSetterWithParameter(psiMethod, newName, newPropertyName, oldParameterName, manager, allRenames);
           return true;
         }
       });
-      allRenames.put(method, newName);
+      
+      addGetterOrSetterWithParameter(method, newName, newPropertyName, oldParameterName, manager, allRenames);
+    }
+  }
+
+  public static void addGetterOrSetterWithParameter(@NotNull PsiMethod methodPrototype,
+                                                    @NotNull String newName,
+                                                    @Nullable String newPropertyName,
+                                                    @NotNull String oldParameterName,
+                                                    @NotNull JavaCodeStyleManager manager,
+                                                    @NotNull Map<PsiElement, String> allRenames) {
+    
+    allRenames.put(methodPrototype, newName);
+    if (newPropertyName != null) {
+      final PsiParameter[] parameters = methodPrototype.getParameterList().getParameters();
+      LOG.assertTrue(parameters.length > 0, methodPrototype.getName());
+      PsiParameter parameter = parameters[0];
+      if (shouldRenameSetterParameter(manager, oldParameterName , methodPrototype)) {
+        allRenames.put(parameter, manager.propertyNameToVariableName(newPropertyName, VariableKind.PARAMETER));
+      }
     }
   }
 
index 8081efe89c3d9daf28d22314f76b3e3600711101..7d113d760938b83c0ca5c012a94e2ea8211a7d17 100644 (file)
@@ -23,6 +23,7 @@ import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.wm.ToolWindowId;
 import com.intellij.openapi.wm.ToolWindowManager;
 import com.intellij.psi.*;
+import com.intellij.psi.codeStyle.JavaCodeStyleManager;
 import com.intellij.psi.util.PsiUtilCore;
 import com.intellij.refactoring.BaseRefactoringProcessor;
 import com.intellij.refactoring.typeMigration.ui.FailedConversionsDialog;
@@ -36,11 +37,13 @@ import com.intellij.usageView.UsageViewManager;
 import com.intellij.util.Consumer;
 import com.intellij.util.IncorrectOperationException;
 import com.intellij.util.SmartList;
+import gnu.trove.THashSet;
 import org.jetbrains.annotations.NotNull;
 
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Set;
 
 import static com.intellij.util.ObjectUtils.assertNotNull;
 
@@ -59,10 +62,19 @@ public class TypeMigrationProcessor extends BaseRefactoringProcessor {
     myRules = rules;
   }
 
+
+  public static void runHighlightingTypeMigration(final Project project,
+                                                          final Editor editor,
+                                                          final TypeMigrationRules rules,
+                                                          final PsiElement root) {
+    runHighlightingTypeMigration(project, editor, rules, root, false);
+  }
+
   public static void runHighlightingTypeMigration(final Project project,
-                                                  final Editor editor,
-                                                  final TypeMigrationRules rules,
-                                                  final PsiElement root) {
+                                                          final Editor editor,
+                                                          final TypeMigrationRules rules,
+                                                          final PsiElement root,
+                                                          final boolean optimizeImports) {
     final PsiFile containingFile = root.getContainingFile();
     final TypeMigrationProcessor processor = new TypeMigrationProcessor(project, root, rules) {
       @Override
@@ -89,6 +101,20 @@ public class TypeMigrationProcessor extends BaseRefactoringProcessor {
             }
           });
         }
+        if (optimizeImports) {
+          final JavaCodeStyleManager javaCodeStyleManager = JavaCodeStyleManager.getInstance(myProject);
+          final Set<PsiFile> affectedFiles = new THashSet<PsiFile>();
+          for (UsageInfo usage : usages) {
+            final PsiFile usageFile = usage.getFile();
+            if (usageFile != null) {
+              affectedFiles.add(usageFile);
+            }
+          }
+          for (PsiFile file : affectedFiles) {
+            javaCodeStyleManager.optimizeImports(file);
+            javaCodeStyleManager.shortenClassReferences(file);
+          }
+        }
       }
     };
     processor.run();
index 02c8284d8f2860a0dab1b26b970cf34a261d5bf4..d588511fc68aeebbb53712e42599cc0440c4451c 100644 (file)
@@ -193,7 +193,7 @@ class TypeMigrationStatementProcessor extends JavaRecursiveElementVisitor {
       final PsiType valueType = myTypeEvaluator.evaluateType(value);
 
       if (returnType != null && valueType != null) {
-        if (!myLabeler.addMigrationRoot(method, valueType, myStatement, TypeConversionUtil.isAssignable(returnType, valueType), true)
+        if (!myLabeler.addMigrationRoot(method, valueType, myStatement, TypeConversionUtil.isAssignable(returnType, valueType), true, true)
             && TypeMigrationLabeler.typeContainsTypeParameters(returnType)) {
           value.accept(this);
         }
index 052d27ab66c06e147df98ba1cc985fd8e6c16ac1..fc89af15194332afaf9b7cb2194d27210d1c0c09 100644 (file)
  */
 package com.intellij.refactoring.typeMigration.rules;
 
+import com.intellij.openapi.util.Comparing;
 import com.intellij.psi.*;
 import com.intellij.psi.util.InheritanceUtil;
 import com.intellij.psi.util.TypeConversionUtil;
 import com.intellij.refactoring.typeMigration.TypeConversionDescriptorBase;
 import com.intellij.refactoring.typeMigration.TypeMigrationLabeler;
+import com.intellij.util.IncorrectOperationException;
 
 /**
  * @author anna
@@ -47,6 +49,24 @@ public class RootTypeConversionRule extends TypeConversionRule {
         }
         if (replacer != null && TypeConversionUtil.areTypesConvertible(method.getReturnType(), replacer.getReturnType())) {
           final PsiElement parent = context.getParent();
+          if (context instanceof PsiMethodReferenceExpression) {
+            final PsiType functionalInterfaceType = ((PsiMethodReferenceExpression)context).getFunctionalInterfaceType();
+            if (Comparing.equal(functionalInterfaceType, to) && method.isEquivalentTo(LambdaUtil.getFunctionalInterfaceMethod(from))) {
+              return new TypeConversionDescriptorBase() {
+                @Override
+                public PsiExpression replace(PsiExpression expression) throws IncorrectOperationException {
+                  final PsiMethodReferenceExpression methodReferenceExpression = (PsiMethodReferenceExpression)expression;
+                  final PsiExpression qualifierExpression = methodReferenceExpression.getQualifierExpression();
+                  if (qualifierExpression != null) {
+                    return (PsiExpression)expression.replace(qualifierExpression);
+                  }
+                  else {
+                    return expression;
+                  }
+                }
+              };
+            }
+          }
           if (context instanceof PsiReferenceExpression && parent instanceof PsiMethodCallExpression) {
             final JavaResolveResult resolveResult = ((PsiReferenceExpression)context).advancedResolve(false);
             final PsiSubstitutor aSubst;
index b0d32553d8ea5710d9fd16ef53b0fcbca8f1876a..c4b4d194b3bf751353047ae7caaa86c3a0c4e609 100644 (file)
@@ -192,6 +192,15 @@ public class JavaUsageTypeProvider implements UsageTypeProviderEx {
 
     if (PsiTreeUtil.getParentOfType(element, PsiClassObjectAccessExpression.class) != null) return UsageType.CLASS_CLASS_OBJECT_ACCESS;
 
+    final PsiMethodReferenceExpression methodReferenceExpression = PsiTreeUtil.getParentOfType(element, PsiMethodReferenceExpression.class);
+    if (methodReferenceExpression != null && methodReferenceExpression.isConstructor()) {
+      final PsiElement qualifier = methodReferenceExpression.getQualifier();
+      if (qualifier instanceof PsiTypeElement && ((PsiTypeElement)qualifier).getType() instanceof PsiArrayType) {
+        return UsageType.CLASS_NEW_ARRAY;
+      }
+      return UsageType.CLASS_NEW_OPERATOR;
+    }
+
     if (element instanceof PsiReferenceExpression) {
       PsiReferenceExpression expression = (PsiReferenceExpression)element;
       if (expression.resolve() instanceof PsiClass) {
index 128b96f4b0af76e5042693235919f9c16cdf5d8e..f3cf54df50832ba69f737388d1f8d4e6d5483be7 100644 (file)
@@ -364,7 +364,8 @@ public class JavaFunctionalExpressionSearcher extends QueryExecutorBase<PsiFunct
     @Override
     public boolean process(VirtualFile file, Collection<JavaFunctionalExpressionIndex.IndexHolder> holders) {
       for (JavaFunctionalExpressionIndex.IndexHolder holder : holders) {
-        if (holder.getLambdaParamsNumber() == myExpectedFunExprParamsCount) {
+        final int lambdaParamsNumber = holder.getLambdaParamsNumber();
+        if (lambdaParamsNumber == myExpectedFunExprParamsCount || lambdaParamsNumber == -1) {
           final boolean suitableParamNumbers;
           if (myVarArgs) {
             suitableParamNumbers = holder.getMethodArgsLength() >= myParametersCount - 1;
index 3eec614acb26b074bc0110b8fbb119a032c59df3..3f184ea5064094da46bce0f28157f8286ad20a41 100644 (file)
@@ -32,7 +32,7 @@ import java.util.*;
 public class PsiIntersectionType extends PsiType.Stub {
   private final PsiType[] myConjuncts;
 
-  protected PsiIntersectionType(@NotNull PsiType[] conjuncts) {
+  private PsiIntersectionType(@NotNull PsiType[] conjuncts) {
     super(PsiAnnotation.EMPTY_ARRAY);
     myConjuncts = conjuncts;
   }
@@ -67,7 +67,7 @@ public class PsiIntersectionType extends PsiType.Stub {
     }
   }
 
-  protected static Set<PsiType> flatten(PsiType[] conjuncts, Set<PsiType> types) {
+  public static Set<PsiType> flatten(PsiType[] conjuncts, Set<PsiType> types) {
     for (PsiType conjunct : conjuncts) {
       if (conjunct instanceof PsiIntersectionType) {
         PsiIntersectionType type = (PsiIntersectionType)conjunct;
@@ -85,8 +85,7 @@ public class PsiIntersectionType extends PsiType.Stub {
         for (PsiType existing : array) {
           if (type != existing) {
             final boolean allowUncheckedConversion = type instanceof PsiClassType && ((PsiClassType)type).isRaw();
-            if (TypeConversionUtil.isAssignable(type, existing, allowUncheckedConversion) ||
-                TypeConversionUtil.isAssignable(GenericsUtil.eliminateWildcards(type), GenericsUtil.eliminateWildcards(existing), allowUncheckedConversion)) {
+            if (TypeConversionUtil.isAssignable(type, existing, allowUncheckedConversion)) {
               iterator.remove();
               break;
             }
index 0ae0fd87a5f8f42fe4b009fc0ccf8627ffea4113..88012cfaa3ed5d4e53bb5b51c8f41f47093a8860 100644 (file)
@@ -259,6 +259,9 @@ public class TypesDistinctProver {
     else if (bound instanceof PsiWildcardType) {
       final PsiType boundBound = ((PsiWildcardType)bound).getBound();
       if (boundBound != null && !boundBound.equals(type)) {
+        if (boundBound instanceof PsiArrayType && !((PsiWildcardType)bound).isSuper()) {
+          return proveArrayTypeDistinct(type, boundBound);
+        }
         final PsiClass psiClass = PsiUtil.resolveClassInClassTypeOnly(boundBound);
         if (psiClass == null) {
           return true;
index 653d5e15c9aecd64a71d429e0156d3f51bb03e31..e4cea2b2250f9282ad7d1ef469981dc5f54049db 100644 (file)
@@ -12,5 +12,6 @@
     <orderEntry type="module" module-name="core-impl" exported="" />
     <orderEntry type="module" module-name="resources-en" />
     <orderEntry type="library" name="asm5" level="project" />
+    <orderEntry type="library" name="Guava" level="project" />
   </component>
 </module>
\ No newline at end of file
index b770f58398350fbbad14291fdc67957533c4b17e..51536ad28103fbdb1761705e2caa1f4bd528b3dc 100644 (file)
@@ -233,7 +233,12 @@ public class ClassInnerStuffCache {
   private PsiMethod getSyntheticMethod(String text) {
     PsiElementFactory factory = JavaPsiFacade.getInstance(myClass.getProject()).getElementFactory();
     PsiMethod method = factory.createMethodFromText(text, myClass);
-    return new LightMethod(myClass.getManager(), method, myClass);
+    return new LightMethod(myClass.getManager(), method, myClass) {
+      @Override
+      public int getTextOffset() {
+        return myClass.getTextOffset();
+      }
+    };
   }
 
   public void dropCaches() {
index 40bf53507b54427f3aec125e1def98842b34a4e6..edf53a6179b9d8f1dcb2db57694133bff34f62a7 100644 (file)
@@ -177,16 +177,19 @@ public class FunctionalInterfaceParameterizationUtil {
       for (int i = 0; i < parameters.length; i++) {
         PsiType paramType = parameters[i];
         if (paramType instanceof PsiWildcardType) {
-          final PsiType bound = GenericsUtil.eliminateWildcards(((PsiWildcardType)paramType).getBound(), false, false);
+          for (PsiClassType paramBound : typeParameters[i].getExtendsListTypes()) {
+            if (PsiPolyExpressionUtil.mentionsTypeParameters(paramBound, typeParametersSet)) {
+              return null;
+            }
+          }
+          final PsiType bound = ((PsiWildcardType)paramType).getBound();
           if (((PsiWildcardType)paramType).isSuper()) {
             newParameters[i] = bound;
           }
           else {
             newParameters[i] = bound != null ? bound : PsiType.getJavaLangObject(psiClass.getManager(), psiClassType.getResolveScope());
             for (PsiClassType paramBound : typeParameters[i].getExtendsListTypes()) {
-              if (!PsiPolyExpressionUtil.mentionsTypeParameters(paramBound, typeParametersSet)) {
-                newParameters[i] = GenericsUtil.getGreatestLowerBound(newParameters[i], paramBound);
-              }
+              newParameters[i] = GenericsUtil.getGreatestLowerBound(newParameters[i], paramBound);
             }
           }
         } else {
index 4f9d1f7f4837632ca98be09931d8fd48a6498c89..b60a12e04e651e6b840f241e0c989eb8065d94a8 100644 (file)
@@ -265,9 +265,17 @@ public class InferenceIncorporationPhase {
    */
   private void upDown(List<PsiType> eqBounds, List<PsiType> upperBounds, PsiSubstitutor substitutor) {
     for (PsiType upperBound : upperBounds) {
-      if (upperBound == null) continue;
+      if (upperBound == null || PsiType.NULL.equals(upperBound) || upperBound instanceof PsiWildcardType) continue;
+
+      if (upperBound instanceof PsiCapturedWildcardType) {
+        upperBound = ((PsiCapturedWildcardType)upperBound).getUpperBound();
+      }
+
       for (PsiType eqBound : eqBounds) {
-        if (eqBound == null) continue;
+        if (eqBound == null || PsiType.NULL.equals(eqBound) || eqBound instanceof PsiWildcardType) continue;
+        if (eqBound instanceof PsiCapturedWildcardType) {
+          eqBound = ((PsiCapturedWildcardType)eqBound).getUpperBound();
+        }
         addConstraint(new StrictSubtypingConstraint(substitutor.substitute(upperBound), substitutor.substitute(eqBound)));
       }
     }
index fcae875ef1a7b547315733d49389228a4eee0d33..2d575e14bb6aa5cd6f32a48789ef898bab602e93 100644 (file)
  */
 package com.intellij.psi.impl.source.tree.java;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.intellij.lang.ASTNode;
 import com.intellij.openapi.diagnostic.LogUtil;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Comparing;
+import com.intellij.openapi.util.Condition;
 import com.intellij.openapi.util.TextRange;
 import com.intellij.pom.java.LanguageLevel;
 import com.intellij.psi.*;
@@ -47,6 +49,7 @@ import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.psi.util.PsiUtil;
 import com.intellij.psi.util.TypeConversionUtil;
 import com.intellij.util.*;
+import com.intellij.util.containers.ContainerUtil;
 import gnu.trove.THashSet;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -486,17 +489,37 @@ public class PsiReferenceExpressionImpl extends PsiReferenceExpressionBase imple
     PsiScopesUtil.resolveAndWalk(filterProcessor, this, null, true);
   }
 
-  public static boolean seemsScrambled(PsiClass aClass) {
-    if (!(aClass instanceof PsiCompiledElement)) {
-      return false;
-    }
+  public static boolean seemsScrambled(@Nullable PsiClass aClass) {
+    return aClass instanceof PsiCompiledElement && seemsScrambledByStructure(aClass);
+  }
 
+  @VisibleForTesting
+  public static boolean seemsScrambledByStructure(@NotNull PsiClass aClass) {
     PsiClass containingClass = aClass.getContainingClass();
-    if (containingClass != null && !seemsScrambled(containingClass)) {
+    if (containingClass != null && !seemsScrambledByStructure(containingClass)) {
       return false;
     }
 
-    final String name = aClass.getName();
+    if (seemsScrambled(aClass.getName())) {
+      List<PsiMethod> methods = ContainerUtil.filter(aClass.getMethods(), new Condition<PsiMethod>() {
+        @Override
+        public boolean value(PsiMethod method) {
+          return !method.hasModifierProperty(PsiModifier.PRIVATE);
+        }
+      });
+
+      return !methods.isEmpty() && ContainerUtil.and(methods, new Condition<PsiMethod>() {
+        @Override
+        public boolean value(PsiMethod method) {
+          return seemsScrambled(method.getName());
+        }
+      });
+    }
+
+    return false;
+  }
+
+  private static boolean seemsScrambled(String name) {
     return name != null && !name.isEmpty() && name.length() <= 2;
   }
 
index 3b487cf7c8ccd515cd828501ac3c057e6e84e5c5..81b2c5ed8009c749f84b5f9c58a51fc07814388a 100644 (file)
@@ -82,6 +82,7 @@ generics.type.argument.cannot.be.of.primitive.type=Type argument cannot be of pr
 generics.unchecked.assignment=Unchecked assignment: ''{0}'' to ''{1}''
 generics.unchecked.cast=Unchecked cast: ''{0}'' to ''{1}''
 generics.unchecked.call.to.member.of.raw.type=Unchecked call to ''{0}'' as a member of raw type ''{1}''
+generics.unchecked.call=Unchecked method ''{0}'' invocation
 generics.diamond.not.applicable=Diamond operator is not applicable for non-parameterized types
 generics.reference.parameters.not.allowed=Reference parameters are not allowed here
 foreach.not.applicable=foreach not applicable to type ''{0}''
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ProvablyDistinctForWildcardsWithArrayBounds.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ProvablyDistinctForWildcardsWithArrayBounds.java
new file mode 100644 (file)
index 0000000..c5d62f1
--- /dev/null
@@ -0,0 +1,9 @@
+class Test {
+  public static <T> void fooBar(final Class<?> aClass,
+                                final Class<? super Number[]> aSuperClass,
+                                final Class<? extends Number[]> anExtendsClass) {
+    Class<T[]> klazz = (Class<T[]>) aClass;
+               klazz = <error descr="Inconvertible types; cannot cast 'java.lang.Class<capture<? super java.lang.Number[]>>' to 'java.lang.Class<T[]>'">(Class<T[]>) aSuperClass</error>;
+               klazz = (Class<T[]>) anExtendsClass;
+  }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/UncheckedWarningsWhenInferredTypeLeadsToRawRoGenericAssignment.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/UncheckedWarningsWhenInferredTypeLeadsToRawRoGenericAssignment.java
new file mode 100644 (file)
index 0000000..b5b1ef6
--- /dev/null
@@ -0,0 +1,13 @@
+import java.util.ArrayList;
+
+class Test {
+
+  static <T extends ArrayList<String>> T foo() {return null;}
+
+  static class Raw extends ArrayList {}
+
+  public static void main(String[] args) {
+    Raw r = <warning descr="Unchecked method 'foo()' invocation">foo</warning>();
+    System.out.println(r);
+  }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/findUsages/ClassFromJdkMethodRef.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/findUsages/ClassFromJdkMethodRef.java
new file mode 100644 (file)
index 0000000..40acbd5
--- /dev/null
@@ -0,0 +1,10 @@
+class Test{
+
+  public void main(java.util.List<String> list) {
+    list.stream().filter(this::bar)
+  }
+  
+  public boolean bar() {
+    return true;
+  }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/EliminateIntersectionTypeWildcardElimination.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/EliminateIntersectionTypeWildcardElimination.java
new file mode 100644 (file)
index 0000000..8bd1bb5
--- /dev/null
@@ -0,0 +1,13 @@
+import java.util.Map;
+
+class Main {
+
+  public static <T extends Map<? extends String, ? extends String>> T test() {
+    return null;
+  }
+
+  public static void main(String[] args) {
+    Map<String, String> m = Main.test();
+  }
+}
+
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/IncorporationOfBoundsAsTypeArguments.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/IncorporationOfBoundsAsTypeArguments.java
new file mode 100644 (file)
index 0000000..b55a7b9
--- /dev/null
@@ -0,0 +1,20 @@
+
+import java.util.*;
+
+class Test {
+  public static void main(String[] args) {
+    Factory factory = new Factory();
+    final Class<? extends ClassB> bClass = null;
+    ClassB b   = factory.create(bClass);
+    String str = factory.create<error descr="'create(java.lang.Class<T>)' in 'Test.Factory' cannot be applied to '(java.lang.Class<capture<? extends Test.ClassB>>)'">(bClass)</error>;
+  }
+
+  public static class Factory {
+    <T extends ClassA<I>, I extends List<String>> T create(Class<T> pClassA) {
+      return null;
+    }
+  }
+
+  interface ClassA<T extends List<String>> {}
+  interface ClassB extends ClassA<ArrayList<String>> {}
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/IncorporationWithRawSubstitutors.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/IncorporationWithRawSubstitutors.java
new file mode 100644 (file)
index 0000000..d6fd804
--- /dev/null
@@ -0,0 +1,26 @@
+import java.io.Serializable;
+import java.util.function.BiFunction;
+
+class Test {
+
+  interface HasCode<T extends Serializable> {
+
+    static <U extends Serializable, T extends Enum<T> & HasCode<U>> T fromCode(U code, Class<T> classEnum) {
+      return null;
+    }
+  }
+
+  enum EnumRaw implements HasCode{
+    RAW_VALUE1;
+  }
+
+  public static <T, U extends Serializable, R> R checkExpected(BiFunction<T, U, R> funct, T param, U secondParam, R expectedResult){
+    R result = funct.apply(param, secondParam);
+    return result;
+  }
+
+  public static void main(String[] args){
+    checkExpected(HasCode::fromCode, "RAW_VALUE2", EnumRaw.class, EnumRaw.RAW_VALUE1);
+  }
+
+}
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/RawInferredTypeCheck.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/RawInferredTypeCheck.java
new file mode 100644 (file)
index 0000000..df0d8d2
--- /dev/null
@@ -0,0 +1,20 @@
+import java.io.Serializable;
+import java.util.function.BiConsumer;
+
+class Test {
+
+  interface HasCode<T extends Serializable> {
+    static <U extends Serializable, T extends Enum<T> & HasCode<U>> T fromCode(U code, Class<T> classEnum) {
+      return null;
+    }
+  }
+
+  enum EnumRaw implements HasCode {
+    ;
+  }
+
+  public static void main(String[] args){
+    final BiConsumer<String, Class<EnumRaw>> code = HasCode::fromCode;
+  }
+
+}
index fa9df550e9361086b8335552bd2f2f8f08c83b18..55ba03955d9a189244bfcb7d4bd3e36320593db3 100644 (file)
@@ -7,16 +7,16 @@ class SimpleDependency  {
   }
 
   {
-    I<? extends String, ? extends  String> k = () -> null;
-    I<? extends String, String> k1 = () -> null;
-    I<? extends List<String>, List<String>> k2 = () -> null;
-    I<? extends List<String>, ? extends List<String>> k3 = () -> null;
+    I<? extends String, ? extends  String> k = <error descr="Cannot infer functional interface type">() -> null</error>;
+    I<? extends String, String> k1 = <error descr="Cannot infer functional interface type">() -> null</error>;
+    I<? extends List<String>, List<String>> k2 = <error descr="Cannot infer functional interface type">() -> null</error>;
+    I<? extends List<String>, ? extends List<String>> k3 = <error descr="Cannot infer functional interface type">() -> null</error>;
     I<? extends List<? extends String>, ? extends List<String>> k4 = <error descr="Cannot infer functional interface type">() -> null</error>;
-    I<? extends List<? extends String>, List<? extends String>> k5 = () -> null;
-    I<? extends List<? extends String>, ? extends List<? extends String>> k6 = () -> null;
+    I<? extends List<? extends String>, List<? extends String>> k5 = <error descr="Cannot infer functional interface type">() -> null</error>;
+    I<? extends List<? extends String>, ? extends List<? extends String>> k6 = <error descr="Cannot infer functional interface type">() -> null</error>;
 
-    I<? super String, String> s = () -> null;
-    I<? super List<String>, List<? extends String>> s1 = () -> null;
+    I<? super String, String> s = <error descr="Cannot infer functional interface type">() -> null</error>;
+    I<? super List<String>, List<? extends String>> s1 = <error descr="Cannot infer functional interface type">() -> null</error>;
   }
 }
 
@@ -43,11 +43,11 @@ class ExtendsList {
 
     I<? extends List<?>, String> e1 = <error descr="Cannot infer functional interface type">() -> null</error>;
     I<? extends List<?>, ?> e2 = <error descr="Cannot infer functional interface type">() -> null</error>;
-    I<? extends List<String>, ? extends String> e3 = () -> null;
+    I<? extends List<String>, ? extends String> e3 = <error descr="Cannot infer functional interface type">() -> null</error>;
     I<? extends List<? extends String>, ? extends String> e4 = <error descr="Cannot infer functional interface type">() -> null</error>;
 
-    I<? super List<String>, ? extends String> s1 = () -> null;
-    I<? super List<String>, String> s2 = () -> null;
+    I<? super List<String>, ? extends String> s1 = <error descr="Cannot infer functional interface type">() -> null</error>;
+    I<? super List<String>, String> s2 = <error descr="Cannot infer functional interface type">() -> null</error>;
   }
 }
 
@@ -63,8 +63,8 @@ class MultipleBounds {
 
     I<? extends List<String>, ? extends String> e1 = <error descr="Cannot infer functional interface type">() -> null</error>;
     I<? extends Comparable<String>, ? extends String> e2 = <error descr="Cannot infer functional interface type">() -> null</error>;
-    I<? extends LC<String>, ? extends String> e3 = () -> null;
-    I<? extends LC<String>, String> e4 = () -> null;
+    I<? extends LC<String>, ? extends String> e3 = <error descr="Cannot infer functional interface type">() -> null</error>;
+    I<? extends LC<String>, String> e4 = <error descr="Cannot infer functional interface type">() -> null</error>;
     I<? extends LC<? extends String>, String> e5 = <error descr="Cannot infer functional interface type">() -> null</error>;
   }
 }
@@ -80,9 +80,9 @@ class FirstIndependentBound {
     I<?, String> n = <error descr="Cannot infer functional interface type">() -> null</error>;
 
     I<? extends List<String>, ? extends String> e1 = <error descr="Cannot infer functional interface type">() -> null</error>;
-    I<? extends Comparable<String>, ? extends String> e2 = () -> null;
-    I<? extends LC<String>, ? extends String> e3 = () -> null;
-    I<? extends LC<String>, String> e4 = () -> null;
+    I<? extends Comparable<String>, ? extends String> e2 = <error descr="Cannot infer functional interface type">() -> null</error>;
+    I<? extends LC<String>, ? extends String> e3 = <error descr="Cannot infer functional interface type">() -> null</error>;
+    I<? extends LC<String>, String> e4 = <error descr="Cannot infer functional interface type">() -> null</error>;
     I<? extends LC<? extends String>, String> e5 = <error descr="Cannot infer functional interface type">() -> null</error>;
   }
 }
@@ -98,10 +98,10 @@ class SecondIndependentBound {
   {
     I<?, String> n = <error descr="Cannot infer functional interface type">() -> null</error>;
 
-    I<? extends List<String>, ? extends String> e1 = () -> null;
+    I<? extends List<String>, ? extends String> e1 = <error descr="Cannot infer functional interface type">() -> null</error>;
     I<? extends Comparable<String>, ? extends String> e2 = <error descr="Cannot infer functional interface type">() -> null</error>;
-    I<? extends LC<String>, ? extends String> e3 = () -> null;
-    I<? extends LC<String>, String> e4 = () -> null;
+    I<? extends LC<String>, ? extends String> e3 = <error descr="Cannot infer functional interface type">() -> null</error>;
+    I<? extends LC<String>, String> e4 = <error descr="Cannot infer functional interface type">() -> null</error>;
     I<? extends LC<? extends String>, String> e5 = <error descr="Cannot infer functional interface type">()  -> null</error>;
     I<? extends LC<? extends String>, ? extends String> e6 = <error descr="Cannot infer functional interface type">()  -> null</error>;
   }
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/staticImportMethod/afterOverloads.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/staticImportMethod/afterOverloads.java
new file mode 100644 (file)
index 0000000..0393e8a
--- /dev/null
@@ -0,0 +1,35 @@
+// "Static import method..." "true"
+package foo;
+
+import static foo.B.a;
+
+public class X {
+    {
+        a("");
+    }
+}
+
+class B {
+  
+  public static  Integer a(Integer i) {
+    return 1;
+  }
+
+  public static  Integer a() {
+    return 1;
+  }
+
+  public static  Integer a(String s) {
+    return 1;
+  }
+  
+  public static  Integer a(String s, String s) {
+    return 1;
+  }
+}
+
+class A {
+  public static  Integer a(String s) {
+    return 1;
+  }
+}
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/staticImportMethod/beforeOverloads.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/staticImportMethod/beforeOverloads.java
new file mode 100644 (file)
index 0000000..77687b1
--- /dev/null
@@ -0,0 +1,33 @@
+// "Static import method..." "true"
+package foo;
+
+public class X {
+    {
+        <caret>a("");
+    }
+}
+
+class B {
+  
+  public static  Integer a(Integer i) {
+    return 1;
+  }
+
+  public static  Integer a() {
+    return 1;
+  }
+
+  public static  Integer a(String s) {
+    return 1;
+  }
+  
+  public static  Integer a(String s, String s) {
+    return 1;
+  }
+}
+
+class A {
+  public static  Integer a(String s) {
+    return 1;
+  }
+}
diff --git a/java/java-tests/testData/codeInsight/slice/backward/TryCatchFinally.java b/java/java-tests/testData/codeInsight/slice/backward/TryCatchFinally.java
new file mode 100644 (file)
index 0000000..df38d98
--- /dev/null
@@ -0,0 +1,17 @@
+package x;
+
+class X {
+  void f(Throwable p) {
+    Throwable error = <flown1>null;
+
+    try {
+      f(p);
+    }
+    catch (Throwable <flown21>e) {
+      error = <flown2>e;
+    }
+    finally {
+      f(<caret>error);
+    }
+  }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/refactoring/renameField/afterOverridingSetterParameterRenamed.java b/java/java-tests/testData/refactoring/renameField/afterOverridingSetterParameterRenamed.java
new file mode 100644 (file)
index 0000000..daf4812
--- /dev/null
@@ -0,0 +1,15 @@
+interface I {
+  void setBar(int o);
+}
+
+interface Foo {
+  void setBar(int bar);
+}
+
+class Bar implements Foo, I {
+  int bar;
+
+  public void setBar(int bar) {
+    this.bar = bar;
+  }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/refactoring/renameField/beforeOverridingSetterParameterRenamed.java b/java/java-tests/testData/refactoring/renameField/beforeOverridingSetterParameterRenamed.java
new file mode 100644 (file)
index 0000000..82e0587
--- /dev/null
@@ -0,0 +1,16 @@
+interface I {
+  void setFoo(int o);
+}
+
+interface Foo {
+  void setFoo(int foo);
+}
+
+class Bar implements Foo, I {
+  int fo<caret>o;
+
+  @Override
+  public void setFoo(int foo) {
+    this.foo = foo;
+  }
+}
\ No newline at end of file
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SeemsScrambledTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SeemsScrambledTest.groovy
new file mode 100644 (file)
index 0000000..c232078
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.codeInsight.completion
+
+import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
+
+import static com.intellij.psi.impl.source.tree.java.PsiReferenceExpressionImpl.seemsScrambledByStructure
+/**
+ * @author peter
+ */
+class SeemsScrambledTest extends LightCodeInsightFixtureTestCase {
+
+  public void "test Id annotation"() {
+    assert !seemsScrambledByStructure(myFixture.addClass('public @interface Id {}'))
+  }
+
+  public void "test inner enum"() {
+    assert !seemsScrambledByStructure(myFixture.addClass('public class Foo { enum v1 {} }').innerClasses[0])
+  }
+
+  public void "test scrambled"() {
+    assert seemsScrambledByStructure(myFixture.addClass('public class a { void b() {} }'))
+  }
+
+  public void "test has non-scrambled method"() {
+    assert !seemsScrambledByStructure(myFixture.addClass('public class a { void doSomething() {} }'))
+  }
+
+}
index dba68689d646f3434a95be7b35a73d28b4c7c171..22f93eb08f538c906f6d3948359db315350237f5 100644 (file)
@@ -536,6 +536,10 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
     doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false);
   }
 
+  public void testProvablyDistinctForWildcardsWithArrayBounds() throws Exception {
+    doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false);
+  }
+
   public void testJavaUtilCollections_NoVerify() throws Exception {
     PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule()));
     assertNotNull(collectionsClass);
index 1018c0706831ea3b82c88304cb61e20a57d472cc..fdccb3c34cdd8d74e49a55be96f53188f7e94294 100644 (file)
@@ -70,6 +70,14 @@ public class FindFunctionalInterfaceTest extends LightCodeInsightFixtureTestCase
   }
 
   public void testClassFromJdk() {
+    doTestIndexSearch("(e) -> true");
+  }
+
+  public void testClassFromJdkMethodRef() {
+    doTestIndexSearch("this::bar");
+  }
+
+  public void doTestIndexSearch(String expected) {
     myFixture.configureByFile(getTestName(false) + ".java");
 
     for (int i = 0; i < JavaFunctionalExpressionSearcher.SMART_SEARCH_THRESHOLD + 5; i++) {
@@ -79,7 +87,7 @@ public class FindFunctionalInterfaceTest extends LightCodeInsightFixtureTestCase
     PsiClass predicate = JavaPsiFacade.getInstance(getProject()).findClass(Predicate.class.getName(), GlobalSearchScope.allScope(getProject()));
     assert predicate != null;
     final PsiFunctionalExpression next = assertOneElement(FunctionalExpressionSearch.search(predicate).findAll());
-    assertEquals("(e) -> true", next.getText());
+    assertEquals(expected, next.getText());
   }
 
   @Override
index 9f10ace0ccce9650cdff4beb248523c79c50dea4..5201367aa1bf15d35fb68b0c5b85e3252df64191 100644 (file)
@@ -873,4 +873,8 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
   public void testExceptionCollectionWithLambda() throws Exception {
     doTest();
   }
+
+  public void testUncheckedWarningsWhenInferredTypeLeadsToRawRoGenericAssignment() throws Exception {
+    doTest(true);
+  }
 }
index 5f049b61decbf617bf50d9e72a7acd6748b4e91f..ecb4270d735c193149ecb965604a5ed8ff0d5aea 100644 (file)
@@ -323,6 +323,18 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
     doTest();
   }
 
+  public void testIncorporationWithRawSubstitutors() throws Exception {
+    doTest();
+  }
+
+  public void testIncorporationOfBoundsAsTypeArguments() throws Exception {
+    doTest();
+  }
+
+  public void testEliminateIntersectionTypeWildcardElimination() throws Exception {
+    doTest();
+  }
+
   private void doTest() throws Exception {
     doTest(false);
   }
index 26d02b495ac3824b243bc633ae9e050e3541f737..b7b5b2fe3bb2fb1108e7223032d5ea6d0ab9e0f2 100644 (file)
@@ -450,6 +450,10 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
     doTest();
   }
 
+  public void testRawInferredTypeCheck() throws Exception {
+    doTest();
+  }
+
   private void doTest() {
     doTest(false);
   }
index 9f1d9b69c410afe8d4270282c74ae5d51f78f147..0d169020bcaf47918073847b0f61badd6c7776c3 100644 (file)
@@ -18,6 +18,7 @@ package com.intellij.find;
 import com.intellij.JavaTestUtil;
 import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase;
 import com.intellij.find.impl.FindInProjectUtil;
+import com.intellij.find.impl.FindResultImpl;
 import com.intellij.find.replaceInProject.ReplaceInProjectManager;
 import com.intellij.lang.properties.IProperty;
 import com.intellij.lang.properties.psi.PropertiesFile;
@@ -29,9 +30,14 @@ import com.intellij.openapi.command.WriteCommandAction;
 import com.intellij.openapi.fileEditor.FileDocumentManager;
 import com.intellij.openapi.fileTypes.FileTypes;
 import com.intellij.openapi.fileTypes.PlainTextFileType;
+import com.intellij.openapi.progress.ProcessCanceledException;
+import com.intellij.openapi.progress.ProgressManager;
+import com.intellij.openapi.progress.util.ProgressIndicatorBase;
 import com.intellij.openapi.project.DumbServiceImpl;
 import com.intellij.openapi.projectRoots.Sdk;
+import com.intellij.openapi.util.Condition;
 import com.intellij.openapi.util.ProperTextRange;
+import com.intellij.openapi.util.Ref;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vfs.LocalFileSystem;
@@ -68,6 +74,10 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.CountDownLatch;
+
+import static com.intellij.find.impl.FindInProjectUtil.buildStringToFindForIndicesFromRegExp;
+import static com.intellij.find.impl.FindInProjectUtil.createFileMaskCondition;
 
 /**
  * @author MYakovlev
@@ -89,7 +99,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
     super.tearDown();
   }
 
-  public void testFindString() {
+  public void testFindString() throws InterruptedException {
     FindModel findModel = FindManagerTestUtils.configureFindModel("done");
 
     String text = "public static class MyClass{\n/*done*/\npublic static void main(){}}";
@@ -139,7 +149,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
     findModel.setProjectScope(true);
 
     final FindResult[] findResultArr = new FindResult[1];
-    findInNewThread(findModel, myFindManager, text, 0, findResultArr);
+    Thread thread = findInNewThread(findModel, myFindManager, text, 0, findResultArr);
     new WaitFor(30 *1000){
       @Override
       protected boolean condition() {
@@ -148,6 +158,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
     }.assertCompleted();
 
     assertFalse(findResultArr[0].isStringFound());
+    thread.join();
   }
 
   private static Thread findInNewThread(final FindModel model,
@@ -836,6 +847,57 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
     assertSize(0, findUsages(findModel));
   }
 
+  public void testRegexReplacementStringForIndices() {
+    assertEquals("public static   MyType my   = 1;", buildStringToFindForIndicesFromRegExp("public static (@A)? MyType my\\w+?  = 1;", myProject));
+    assertEquals(" Foo ", buildStringToFindForIndicesFromRegExp("\\bFoo\\b", myProject));
+    assertEquals("", buildStringToFindForIndicesFromRegExp("foo|bar", myProject));
+  }
+
+  public void testCreateFileMaskCondition() {
+    final Condition<String> condition = createFileMaskCondition("*.java, *.js, !Foo.java, !*.min.js");
+    assertTrue(condition.value("Bar.java"));
+    assertTrue(!condition.value("Bar.javac"));
+    assertTrue(!condition.value("Foo.java"));
+    assertTrue(!condition.value("Foo.jav"));
+    assertTrue(!condition.value("Foo.min.js"));
+    assertTrue(condition.value("Foo.js"));
+  }
+
+  public void testRegExpSearchDoesCheckCancelled() throws InterruptedException {
+    String text = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
+    FindModel findModel = FindManagerTestUtils.configureFindModel("(x+x+)+y");
+    findModel.setRegularExpressions(true);
+
+    runAsyncTest(text, findModel);
+    findModel.setSearchContext(FindModel.SearchContext.IN_COMMENTS);
+    runAsyncTest("/*" + text + "*/", findModel);
+  }
+
+  private void runAsyncTest(String text, FindModel findModel) throws InterruptedException {
+    final Ref<FindResult> result = new Ref<>();
+    final CountDownLatch progressStarted = new CountDownLatch(1);
+    final ProgressIndicatorBase progressIndicatorBase = new ProgressIndicatorBase();
+    final Thread thread = new Thread(() -> {
+      ProgressManager.getInstance().runProcess(() -> {
+        try {
+          progressStarted.countDown();
+          result.set(myFindManager.findString(text, 0, findModel, new LightVirtualFile("foo.java")));
+        }
+        catch (ProcessCanceledException ex) {
+          result.set(new FindResultImpl());
+        }
+      }, progressIndicatorBase);
+    });
+    thread.start();
+
+    progressStarted.await();
+    thread.join(100);
+    progressIndicatorBase.cancel();
+    thread.join(500);
+    assertNotNull(result.get());
+    assertTrue(!result.get().isStringFound());
+  }
+
   private void doTestRegexpReplace(String initialText, String searchString, String replaceString, String expectedResult) {
     configureByText(FileTypes.PLAIN_TEXT, initialText);
     FindModel model = new FindModel();
index ab25cd4199611f64cea43d23d5094398362ec61f..4699cf546b3c213b22a6963addf77342e89a24af 100644 (file)
 package com.intellij.navigation;
 
 import com.intellij.codeInsight.TargetElementUtil;
-import com.intellij.psi.CommonClassNames;
-import com.intellij.psi.PsiClass;
-import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiFile;
+import com.intellij.codeInsight.hint.actions.ShowImplementationsAction;
+import com.intellij.ide.DataManager;
+import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Ref;
+import com.intellij.pom.Navigatable;
+import com.intellij.pom.java.LanguageLevel;
+import com.intellij.psi.*;
+import com.intellij.testFramework.builders.JavaModuleFixtureBuilder;
 import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
+import org.jetbrains.annotations.NotNull;
 
 public class ShowImplementationHandlerTest extends JavaCodeInsightFixtureTestCase {
 
+  @Override
+  protected void tuneFixture(JavaModuleFixtureBuilder moduleBuilder) throws Exception {
+    super.tuneFixture(moduleBuilder);
+    moduleBuilder.setLanguageLevel(LanguageLevel.JDK_1_8);
+  }
+
   public void testMultipleImplsFromAbstractCall() throws Throwable {
     PsiFile file = myFixture.addFileToProject("Foo.java", "public abstract class Hello {" +
                                                           "    {" +
@@ -41,4 +53,49 @@ public class ShowImplementationHandlerTest extends JavaCodeInsightFixtureTestCas
     assertEquals(CommonClassNames.JAVA_LANG_RUNNABLE, qualifiedName);
   }
 
+  public void testFunctionExpressionsOnReference() throws Exception {
+    myFixture.addClass("public interface I {void m();}");
+    myFixture.addClass("public class Usage {{I i = () -> {};}}");
+    PsiFile file = myFixture.addFileToProject("Foo.java", "public abstract class Hello {" +
+                                                          "    void foo(I i) {" +
+                                                          "        i.<caret>m();\n" +
+                                                          "    }\n" +
+                                                          "}\n" +
+                                                          "\n");
+    myFixture.configureFromExistingVirtualFile(file.getVirtualFile());
+
+    final PsiElement[] implementations = getImplementations();
+    assertEquals(2, implementations.length);
+    assertInstanceOf(implementations[1], PsiLambdaExpression.class);
+  }
+
+  private static PsiElement[] getImplementations() {
+    final Ref<PsiElement[]> ref = new Ref<>();
+    new ShowImplementationsAction() {
+      @Override
+      protected void showImplementations(@NotNull PsiElement[] impls, @NotNull Project project, String text, Editor editor, PsiFile file,
+                                         PsiElement element,
+                                         boolean invokedFromEditor,
+                                         boolean invokedByShortcut) {
+        ref.set(impls);
+      }
+    }.performForContext(DataManager.getInstance().getDataContext());
+    return ref.get();
+  }
+
+  public void testEnumValuesNavigation() throws Exception {
+    final PsiFile file = myFixture.addFileToProject("Foo.java", "public class Foo {" +
+                                                                "  public enum E {;}" +
+                                                                "  void foo() {" +
+                                                                "    for (E e : E.va<caret>lues()){}" +
+                                                                "  }" +
+                                                                "}");
+    myFixture.configureFromExistingVirtualFile(file.getVirtualFile());
+    final PsiElement element = TargetElementUtil.findTargetElement(myFixture.getEditor(), TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED);
+    assertNotNull(element);
+    assertInstanceOf(element, PsiMethod.class);
+    assertTrue(((Navigatable)element).canNavigate());
+    ((Navigatable)element).navigate(true);
+    assertEquals(32, myFixture.getCaretOffset());
+  }
 }
\ No newline at end of file
index f04dc8491ec9d01d19e984028d249f7661038207..2274af5b711ae731b933d4b6b95afa4310401d20 100644 (file)
@@ -34,7 +34,6 @@ import com.intellij.psi.impl.source.PsiFileImpl;
 import com.intellij.testFramework.LeakHunter;
 import com.intellij.testFramework.PlatformTestCase;
 import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
-import com.intellij.util.Processor;
 
 public class LoadProjectTest extends PlatformTestCase {
   @Override
@@ -82,12 +81,8 @@ public class LoadProjectTest extends PlatformTestCase {
     FileEditorManager.getInstance(getProject()).closeFile(b);
     ProjectManagerEx.getInstanceEx().closeAndDispose(getProject());
 
-    LeakHunter.checkLeak(ApplicationManager.getApplication(), PsiFileImpl.class, new Processor<PsiFileImpl>() {
-      @Override
-      public boolean process(PsiFileImpl psiFile) {
-        return  psiFile.getViewProvider().getVirtualFile().getFileSystem() instanceof LocalFileSystem;
-      }
-    });
+    LeakHunter.checkLeak(ApplicationManager.getApplication(), PsiFileImpl.class,
+                         psiFile -> psiFile.getViewProvider().getVirtualFile().getFileSystem() instanceof LocalFileSystem);
   }
 
   @Override
index ed0ac4de00f3d02492fe3a0a15e26347a9096e98..affd1ffe21e0e9e76842be82913185f6723bd909 100644 (file)
@@ -60,7 +60,8 @@ class AstLeaksTest extends LightCodeInsightFixtureTestCase {
     def sup = myFixture.addFileToProject('sup.java', 'class Super { Super() {} }')
     assert sup.findElementAt(0) // load AST
     assert !((PsiFileImpl)sup).stub
-    LeakHunter.checkLeak(sup, MethodElement)
+
+    LeakHunter.checkLeak(sup, MethodElement, { it.psi.containingFile == sup } as Processor)
 
     def foo = myFixture.addFileToProject('a.java', 'class Foo extends Super { void bar() { bar(); } }')
     myFixture.configureFromExistingVirtualFile(foo.virtualFile)
@@ -69,8 +70,8 @@ class AstLeaksTest extends LightCodeInsightFixtureTestCase {
     assert !((PsiFileImpl)foo).stub
     assert ((PsiFileImpl)foo).treeElement
 
-    LeakHunter.checkLeak(foo, MethodElement)
-    LeakHunter.checkLeak(sup, MethodElement)
+    LeakHunter.checkLeak(foo, MethodElement, { it.psi.containingFile == foo } as Processor)
+    LeakHunter.checkLeak(sup, MethodElement, { it.psi.containingFile == sup } as Processor)
   }
 
   public void "test no hard refs to Default File Template inspection internal AST"() {
index 5e2f89a10f3c6088c42049f938d62f3af9bb3261..94d71a667e7ae4c1e3d768f1df3678f42c8fc0a0 100644 (file)
@@ -110,15 +110,9 @@ public class PsiConcurrencyStressTest extends DaemonAnalyzerTestCase {
     }
 
     assertTrue("Timed out", reads.await(5, TimeUnit.MINUTES));
-    ContainerUtil.process(threads, thread -> {
-      try {
-        thread.join();
-        return true;
-      }
-      catch (InterruptedException e) {
-        throw new RuntimeException(e);
-      }
-    });
+    for (Thread thread : threads) {
+      thread.join();
+    }
   }
 
   private static void mark(final String s) {
index 8e76bf4cb914388d7b7a67ee678255882b1f1066..c9f8d7e760017bd1541bc41fede3b4636bd7d51e 100644 (file)
@@ -15,9 +15,7 @@
  */
 package com.intellij.psi.impl.file.impl;
 
-import com.intellij.ide.IdeEventQueue;
 import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.application.impl.LaterInvocator;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.fileTypes.FileTypeManager;
@@ -193,9 +191,7 @@ public class PsiEventsTest extends PsiTestCase {
           return directory.getVirtualFile().equals(myPrjDir1);
         }
       };
-      LeakHunter.checkLeak(ApplicationManager.getApplication(), PsiDirectory.class, isReallyLeak);
-      LeakHunter.checkLeak(IdeEventQueue.getInstance(), PsiDirectory.class, isReallyLeak);
-      LeakHunter.checkLeak(LaterInvocator.getLaterInvocatorQueue(), PsiDirectory.class, isReallyLeak);
+      LeakHunter.checkLeak(LeakHunter.allRoots(), PsiDirectory.class, isReallyLeak);
 
       String dumpPath = FileUtil.createTempFile(
         new File(System.getProperty("teamcity.build.tempDir", System.getProperty("java.io.tmpdir"))), "testRenameFileWithoutDir", ".hprof",
@@ -792,7 +788,7 @@ public class PsiEventsTest extends PsiTestCase {
     assertTrue(documentManager.isCommitted(document));
   }
 
-  private void checkCommitted(boolean shouldBeCommitted, PsiTreeChangeEvent event) {
+  private static void checkCommitted(boolean shouldBeCommitted, PsiTreeChangeEvent event) {
     PsiFile file = event.getFile();
     PsiDocumentManager documentManager = PsiDocumentManager.getInstance(file.getProject());
     Document document = documentManager.getDocument(file);
index 62e5f327aa11757055f25b83930116ca01f8bb44..0020cb0488f488f89fc4ebbdf6ddd3dbd02020a0 100644 (file)
@@ -64,6 +64,10 @@ public class RenameFieldTest extends LightRefactoringTestCase {
     doTest("utm", "java");
   }
 
+  public void testOverridingSetterParameterRenamed() throws Exception {
+    doTest("bar", "java");
+  }
+
   public void testHidesOuter() throws Exception {
     doTest("x", "java");
   }
index 8d8638dc02d4bff475ca0fd8681afa7a34282ec7..edfa73b4a5cec182e8a7e0618989434393d530eb 100644 (file)
@@ -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.
@@ -17,23 +17,14 @@ package com.intellij.slicer;
 
 import com.intellij.analysis.AnalysisScope;
 import com.intellij.codeInsight.daemon.impl.HighlightInfo;
-import com.intellij.openapi.command.WriteCommandAction;
-import com.intellij.openapi.editor.Document;
-import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.editor.LogicalPosition;
 import com.intellij.openapi.editor.RangeMarker;
-import com.intellij.openapi.fileEditor.FileEditorManager;
-import com.intellij.openapi.progress.ProgressManager;
-import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.psi.PsiDocumentManager;
 import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiFile;
-import com.intellij.util.CommonProcessors;
 import com.intellij.util.containers.IntArrayList;
-import gnu.trove.THashMap;
 import gnu.trove.TIntObjectHashMap;
 
-import java.util.*;
+import java.util.Collection;
+import java.util.Map;
 
 /**
  * @author cdr
@@ -89,4 +80,5 @@ public class SliceBackwardTest extends SliceTestCase {
   public void testVarArgsPartial() throws Exception { doTest();}
 
   public void testListTrackToArray() throws Exception { doTest();}
+  public void testTryCatchFinally() throws Exception { doTest();}
 }
index 0fd721002f4c929ea57bd49953d5d81ff761476b..b04d40638052e17b0d1f0766e04b06ef31461de0 100644 (file)
@@ -31,7 +31,15 @@ public class TypeMigrationVariableTypeFixProvider implements ChangeVariableTypeQ
   }
 
   @NotNull
-  public static VariableTypeFix createTypeMigrationFix(@NotNull final PsiVariable variable, @NotNull final PsiType toReturn) {
+  public static VariableTypeFix createTypeMigrationFix(@NotNull final PsiVariable variable,
+                                                       @NotNull final PsiType toReturn) {
+    return createTypeMigrationFix(variable, toReturn, false);
+  }
+
+  @NotNull
+  public static VariableTypeFix createTypeMigrationFix(@NotNull final PsiVariable variable,
+                                                       @NotNull final PsiType toReturn,
+                                                       final boolean optimizeImports) {
     return new VariableTypeFix(variable, toReturn) {
       @NotNull
       @Override
@@ -45,7 +53,7 @@ public class TypeMigrationVariableTypeFixProvider implements ChangeVariableTypeQ
                          @Nullable("is null when called from inspection") Editor editor,
                          @NotNull PsiElement startElement,
                          @NotNull PsiElement endElement) {
-        runTypeMigrationOnVariable((PsiVariable)startElement, getReturnType(), editor);
+        runTypeMigrationOnVariable((PsiVariable)startElement, getReturnType(), editor, optimizeImports);
       }
 
       @Override
@@ -57,7 +65,8 @@ public class TypeMigrationVariableTypeFixProvider implements ChangeVariableTypeQ
 
   public static void runTypeMigrationOnVariable(@NotNull PsiVariable variable,
                                                 @NotNull PsiType targetType,
-                                                @Nullable("is null when called from inspection") Editor editor) {
+                                                @Nullable("is null when called from inspection") Editor editor,
+                                                boolean optimizeImports) {
     Project project = variable.getProject();
     if (!FileModificationService.getInstance().prepareFileForWrite(variable.getContainingFile())) return;
     try {
@@ -65,7 +74,7 @@ public class TypeMigrationVariableTypeFixProvider implements ChangeVariableTypeQ
       final TypeMigrationRules rules = new TypeMigrationRules(TypeMigrationLabeler.getElementType(variable));
       rules.setMigrationRootType(targetType);
       rules.setBoundScope(GlobalSearchScope.projectScope(project));
-      TypeMigrationProcessor.runHighlightingTypeMigration(project, editor, rules, variable);
+      TypeMigrationProcessor.runHighlightingTypeMigration(project, editor, rules, variable, optimizeImports);
       JavaCodeStyleManager.getInstance(project).shortenClassReferences(variable);
       UndoUtil.markPsiFileForUndo(variable.getContainingFile());
     }
index 439c34666198a2a6ae462a300ff6b96dcb87da57..b08aca469a9062c9d8568df125771d781aefdc44 100644 (file)
@@ -118,11 +118,11 @@ public class GuavaInspection extends BaseJavaLocalInspectionTool {
       public void visitVariable(PsiVariable variable) {
         if (!checkVariables) return;
         final PsiType type = variable.getType();
-        final PsiClassType targetType = getConversionClassType(type);
+        PsiType targetType = getConversionClassType(type);
         if (targetType != null) {
           holder.registerProblem(variable,
                                  PROBLEM_DESCRIPTION_FOR_VARIABLE,
-                                 TypeMigrationVariableTypeFixProvider.createTypeMigrationFix(variable, targetType));
+                                 TypeMigrationVariableTypeFixProvider.createTypeMigrationFix(variable, targetType, true));
         }
       }
 
@@ -130,7 +130,7 @@ public class GuavaInspection extends BaseJavaLocalInspectionTool {
       public void visitMethod(PsiMethod method) {
         super.visitMethod(method);
         if (!checkReturnTypes) return;
-        final PsiClassType targetType = getConversionClassType(method.getReturnType());
+        final PsiType targetType = getConversionClassType(method.getReturnType());
         if (targetType != null) {
           final PsiTypeElement typeElement = method.getReturnTypeElement();
           if (typeElement != null) {
@@ -172,15 +172,18 @@ public class GuavaInspection extends BaseJavaLocalInspectionTool {
         holder.registerProblem(chain, PROBLEM_DESCRIPTION_FOR_METHOD_CHAIN, new MigrateFluentIterableChainQuickFix(chain, initialType, targetType));
       }
 
-      private PsiClassType getConversionClassType(PsiType initialType) {
-        if (initialType instanceof PsiClassType) {
-          final PsiClassType.ClassResolveResult resolveResult = ((PsiClassType)initialType).resolveGenerics();
+      private PsiType getConversionClassType(PsiType initialType) {
+        if (initialType == null) return null;
+        final PsiType type = initialType.getDeepComponentType();
+        if (type instanceof PsiClassType) {
+          final PsiClassType.ClassResolveResult resolveResult = ((PsiClassType)type).resolveGenerics();
           final PsiClass psiClass = resolveResult.getElement();
           if (psiClass != null) {
             final String qName = psiClass.getQualifiedName();
             final PsiClass targetClass = myGuavaClassConversions.getValue().get(qName);
             if (targetClass != null) {
-              return addTypeParameters(initialType, resolveResult, targetClass);
+              final PsiClassType createdType = addTypeParameters(type, resolveResult, targetClass);
+              return initialType instanceof PsiArrayType ? new PsiArrayType(createdType) : createdType;
             }
           }
         }
@@ -220,6 +223,7 @@ public class GuavaInspection extends BaseJavaLocalInspectionTool {
         }
       }
 
+      @NotNull
       private PsiClassType addTypeParameters(PsiType currentType, PsiClassType.ClassResolveResult currentTypeResolveResult, PsiClass targetClass) {
         final Map<PsiTypeParameter, PsiType> substitutionMap = currentTypeResolveResult.getSubstitutor().getSubstitutionMap();
         final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(holder.getProject());
@@ -330,9 +334,9 @@ public class GuavaInspection extends BaseJavaLocalInspectionTool {
 
   public static class MigrateMethodReturnTypeFix extends LocalQuickFixAndIntentionActionOnPsiElement {
 
-    private final PsiClassType myTargetType;
+    private final PsiType myTargetType;
 
-    private MigrateMethodReturnTypeFix(@NotNull PsiMethod method, PsiClassType targetType) {
+    private MigrateMethodReturnTypeFix(@NotNull PsiMethod method, PsiType targetType) {
       super(method);
       myTargetType = targetType;
     }
@@ -349,7 +353,7 @@ public class GuavaInspection extends BaseJavaLocalInspectionTool {
         final TypeMigrationRules rules = new TypeMigrationRules(TypeMigrationLabeler.getElementType(method));
         rules.setMigrationRootType(myTargetType);
         rules.setBoundScope(method.getUseScope());
-        TypeMigrationProcessor.runHighlightingTypeMigration(project, editor, rules, method);
+        TypeMigrationProcessor.runHighlightingTypeMigration(project, editor, rules, method, true);
         UndoUtil.markPsiFileForUndo(file);
       }
       catch (IncorrectOperationException e) {
index 8062e6baabba1b40aa2da0532e759953b5d79524..5b30001450ad261a7e5a741163c1576f79421727 100644 (file)
@@ -18,9 +18,7 @@ package com.intellij.refactoring.typeMigration.intentions;
 import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Comparing;
 import com.intellij.psi.*;
-import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.psi.util.PsiTypesUtil;
 import com.intellij.psi.util.PsiUtil;
 import com.intellij.refactoring.typeMigration.TypeMigrationVariableTypeFixProvider;
@@ -43,7 +41,7 @@ public class ConvertAtomicToLongAdderIntention extends PsiElementBaseIntentionAc
     if (variable != null) {
       final PsiType longAdder =
         JavaPsiFacade.getElementFactory(project).createTypeFromText(LongAdderConversionRule.JAVA_UTIL_CONCURRENT_ATOMIC_LONG_ADDER, element);
-      TypeMigrationVariableTypeFixProvider.runTypeMigrationOnVariable(variable, longAdder, null);
+      TypeMigrationVariableTypeFixProvider.runTypeMigrationOnVariable(variable, longAdder, null, false);
     }
   }
 
index 9c227fb09d33100ecb39c0adcb130255ea7dc9b3..6392f28fb69b5a12b78d6fbed48fdeec91b124d9 100644 (file)
@@ -17,7 +17,6 @@ package com.intellij.refactoring.typeMigration.rules.guava;
 
 import com.intellij.codeInspection.AnonymousCanBeLambdaInspection;
 import com.intellij.psi.*;
-import com.intellij.psi.util.PsiUtil;
 import com.intellij.refactoring.typeMigration.TypeConversionDescriptorBase;
 import com.intellij.refactoring.typeMigration.TypeMigrationLabeler;
 import com.intellij.refactoring.typeMigration.rules.TypeConversionRule;
@@ -27,8 +26,6 @@ import com.intellij.util.containers.hash.HashMap;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Map;
 
 /**
@@ -59,7 +56,8 @@ public abstract class BaseGuavaTypeConversionRule extends TypeConversionRule {
 
   @Nullable
   protected TypeConversionDescriptorBase findConversionForVariableReference(@NotNull PsiReferenceExpression referenceExpression,
-                                                                            @NotNull PsiVariable psiVariable) {
+                                                                            @NotNull PsiVariable psiVariable,
+                                                                            @Nullable PsiExpression context) {
     return null;
   }
 
@@ -82,6 +80,8 @@ public abstract class BaseGuavaTypeConversionRule extends TypeConversionRule {
     if (member instanceof PsiMethod) {
       PsiMethod method = (PsiMethod)member;
       final String methodName = method.getName();
+      final PsiClass aClass = method.getContainingClass();
+      if (!isValidMethodQualifierToConvert(aClass)) return null;
       final TypeConversionDescriptorBase descriptor = mySimpleDescriptors.getValue().get(methodName);
       if (descriptor != null) {
         return descriptor;
@@ -101,16 +101,20 @@ public abstract class BaseGuavaTypeConversionRule extends TypeConversionRule {
     else if (context instanceof PsiReferenceExpression) {
       final PsiElement resolvedElement = ((PsiReferenceExpression)context).resolve();
       if (resolvedElement instanceof PsiVariable) {
-        return findConversionForVariableReference((PsiReferenceExpression)context, (PsiVariable)resolvedElement);
+        return findConversionForVariableReference((PsiReferenceExpression)context, (PsiVariable)resolvedElement, context);
       }
     }
     return null;
   }
 
-  public static boolean canConvert(@Nullable PsiType from,
-                                   @Nullable  PsiType to,
-                                   @NotNull String fromClassName,
-                                   @NotNull String toClassName) {
+  protected boolean isValidMethodQualifierToConvert(PsiClass aClass) {
+    return aClass != null && ruleFromClass().equals(aClass.getQualifiedName());
+  }
+
+  static boolean canConvert(@Nullable PsiType from,
+                            @Nullable PsiType to,
+                            @NotNull String fromClassName,
+                            @NotNull String toClassName) {
     if (!(from instanceof PsiClassType)) {
       return false;
     }
diff --git a/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaConversionUtil.java b/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaConversionUtil.java
new file mode 100644 (file)
index 0000000..a0da3db
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.refactoring.typeMigration.rules.guava;
+
+import com.intellij.psi.*;
+import com.intellij.psi.util.InheritanceUtil;
+import com.intellij.psi.util.PsiTypesUtil;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author Dmitry Batkovich
+ */
+public class GuavaConversionUtil {
+
+  @Nullable
+  public static PsiType getFunctionReturnType(PsiExpression functionExpression) {
+    if (functionExpression instanceof PsiFunctionalExpression) {
+      return LambdaUtil.getFunctionalInterfaceReturnType((PsiFunctionalExpression)functionExpression);
+    }
+    PsiType currentType = functionExpression.getType();
+    if (currentType == null) return null;
+
+    while (true) {
+      if (LambdaUtil.isFunctionalType(currentType)) {
+        return LambdaUtil.getFunctionalInterfaceReturnType(currentType);
+      }
+      final PsiType[] superTypes = currentType.getSuperTypes();
+      currentType = null;
+      for (PsiType type : superTypes) {
+        final PsiClass aClass = PsiTypesUtil.getPsiClass(type);
+        if (aClass != null && InheritanceUtil.isInheritor(aClass, GuavaFunctionConversionRule.GUAVA_FUNCTION)) {
+          currentType = type;
+          break;
+        }
+      }
+      if (currentType == null) {
+        return null;
+      }
+    }
+  }
+
+  @NotNull
+  public static PsiType addTypeParameters(@NotNull String baseClassQualifiedName, @Nullable PsiType type, @NotNull PsiElement context) {
+    String parameterText = "";
+    if (type != null) {
+      final String canonicalText = type.getCanonicalText(false);
+      if (canonicalText.contains("<")) {
+        parameterText = canonicalText.substring(canonicalText.indexOf('<'));
+      }
+    }
+
+    return JavaPsiFacade.getElementFactory(context.getProject()).createTypeFromText(baseClassQualifiedName + parameterText, context);
+  }
+}
index f175f12b45abca3b1f870743dbd7b3a82e1b3869..41f7cae3c9262a49765fdfc02c6d0b100d65d5a8 100644 (file)
@@ -110,6 +110,12 @@ public class GuavaFluentIterableConversionRule extends BaseGuavaTypeConversionRu
     DESCRIPTORS_MAP.put("toSortedSet", new TypeConversionDescriptorFactory("$it$.toSortedSet($c$)", "$it$.sorted($c$).collect(java.util.stream.Collectors.toSet())", false));
   }
 
+  @Override
+  protected boolean isValidMethodQualifierToConvert(PsiClass aClass) {
+    return super.isValidMethodQualifierToConvert(aClass) ||
+           (aClass != null && GuavaOptionalConversionRule.GUAVA_OPTIONAL.equals(aClass.getQualifiedName()));
+  }
+
   @Nullable
   @Override
   protected TypeConversionDescriptorBase findConversionForMethod(@NotNull PsiType from,
@@ -220,7 +226,7 @@ public class GuavaFluentIterableConversionRule extends BaseGuavaTypeConversionRu
         final TypeConversionDescriptor descriptor = base.create();
         needSpecifyType = base.isChainedMethod();
         if (needSpecifyType && !base.isFluentIterableReturnType()) {
-          conversionType = addTypeParameters(GuavaOptionalConversionRule.JAVA_OPTIONAL, context.getType(), context);
+          conversionType = GuavaConversionUtil.addTypeParameters(GuavaOptionalConversionRule.JAVA_OPTIONAL, context.getType(), context);
         }
         descriptorBase = descriptor;
       }
@@ -228,7 +234,7 @@ public class GuavaFluentIterableConversionRule extends BaseGuavaTypeConversionRu
     if (descriptorBase != null) {
       if (needSpecifyType) {
         if (conversionType == null) {
-          conversionType = addTypeParameters(StreamApiConstants.JAVA_UTIL_STREAM_STREAM, context.getType(), context);
+          conversionType = GuavaConversionUtil.addTypeParameters(StreamApiConstants.JAVA_UTIL_STREAM_STREAM, context.getType(), context);
         }
         descriptorBase.withConversionType(conversionType);
       }
@@ -237,19 +243,6 @@ public class GuavaFluentIterableConversionRule extends BaseGuavaTypeConversionRu
     return null;
   }
 
-  @NotNull
-  private static PsiType addTypeParameters(String baseClassQualifiedName, PsiType type, PsiElement context) {
-    String parameterText = "";
-    if (type != null) {
-      final String canonicalText = type.getCanonicalText(false);
-      if (canonicalText.contains("<")) {
-        parameterText = canonicalText.substring(canonicalText.indexOf('<'));
-      }
-    }
-
-    return JavaPsiFacade.getElementFactory(context.getProject()).createTypeFromText(baseClassQualifiedName + parameterText, context);
-  }
-
   @Nullable
   public static GuavaChainedConversionDescriptor buildCompoundDescriptor(PsiMethodCallExpression expression,
                                                                           PsiType to,
@@ -306,7 +299,15 @@ public class GuavaFluentIterableConversionRule extends BaseGuavaTypeConversionRu
         break;
       }
       else if (qualifier instanceof PsiReferenceExpression && ((PsiReferenceExpression)qualifier).resolve() instanceof PsiVariable) {
-        labeler.migrateExpressionType(qualifier, addTypeParameters(StreamApiConstants.JAVA_UTIL_STREAM_STREAM, to, qualifier), qualifier.getParent(), false, false);
+        final PsiClass toClass = PsiTypesUtil.getPsiClass(to);
+        if (toClass != null && (StreamApiConstants.JAVA_UTIL_STREAM_STREAM.equals(toClass.getQualifiedName()) ||
+                                GuavaOptionalConversionRule.JAVA_OPTIONAL.equals(toClass.getQualifiedName()))) {
+          labeler.migrateExpressionType(qualifier,
+                                        GuavaConversionUtil.addTypeParameters(toClass.getQualifiedName(), qualifier.getType(), qualifier),
+                                        qualifier.getParent(),
+                                        false,
+                                        false);
+        }
         break;
       }
       else {
index 5bf7a74ee81954a4373286a80f36272d5b11f75f..35b283351199789c1fa58c38e21234d2c17655bf 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.intellij.refactoring.typeMigration.rules.guava;
 
+import com.intellij.psi.PsiExpression;
 import com.intellij.psi.PsiReferenceExpression;
 import com.intellij.psi.PsiVariable;
 import com.intellij.refactoring.typeMigration.TypeConversionDescriptor;
@@ -29,6 +30,7 @@ import java.util.Map;
  */
 public class GuavaFunctionConversionRule extends BaseGuavaTypeConversionRule {
   public static final String JAVA_UTIL_FUNCTION_FUNCTION = "java.util.function.Function";
+  public static final String GUAVA_FUNCTION = "com.google.common.base.Function";
 
   @Override
   protected void fillSimpleDescriptors(Map<String, TypeConversionDescriptorBase> descriptorsMap) {
@@ -38,14 +40,14 @@ public class GuavaFunctionConversionRule extends BaseGuavaTypeConversionRule {
   @Nullable
   @Override
   protected TypeConversionDescriptorBase findConversionForVariableReference(@NotNull PsiReferenceExpression referenceExpression,
-                                                                            @NotNull PsiVariable psiVariable) {
+                                                                            @NotNull PsiVariable psiVariable, PsiExpression context) {
     return new TypeConversionDescriptor("$f$", "$f$::apply");
   }
 
   @NotNull
   @Override
   public String ruleFromClass() {
-    return "com.google.common.base.Function";
+    return GUAVA_FUNCTION;
   }
 
   @NotNull
index 31244db21f5c622f274fd501d9680795f3819781..7fb5ed6bd1ec47aad7b4d16b6b662d7bdfeb4a68 100644 (file)
@@ -32,6 +32,7 @@ import java.util.Map;
 public class GuavaOptionalConversionRule extends BaseGuavaTypeConversionRule {
   private final static Logger LOG = Logger.getInstance(GuavaOptionalConversionRule.class);
 
+  public final static String OPTIONAL_CONVERTOR_PATTERN = "Optional.fromNullable($o$.orElse(null))";
   public final static String GUAVA_OPTIONAL = "com.google.common.base.Optional";
   public final static String JAVA_OPTIONAL = "java.util.Optional";
 
@@ -43,55 +44,79 @@ public class GuavaOptionalConversionRule extends BaseGuavaTypeConversionRule {
                                                                  @NotNull String methodName,
                                                                  PsiExpression context,
                                                                  TypeMigrationLabeler labeler) {
-    if ("or".equals(methodName)) {
-      PsiMethodCallExpression methodCallExpression = null;
-      if (context instanceof PsiMethodCallExpression) {
+    if (!(context instanceof PsiMethodCallExpression)) {
+      if ("or".equals(methodName)) {
+        PsiMethodCallExpression methodCallExpression = null;
+        if (context.getParent() instanceof PsiMethodCallExpression) {
+          methodCallExpression = (PsiMethodCallExpression)context.getParent();
+        }
+        if (methodCallExpression == null) {
+          return null;
+        }
         final PsiClass aClass = getParameterClass(method);
         if (aClass != null) {
           final String qName = aClass.getQualifiedName();
-          String pattern =
-            GUAVA_OPTIONAL.equals(qName) ? "java.util.Optional.ofNullable($expr$.get())" : "java.util.Optional.ofNullable($expr$)";
-          return new TypeConversionDescriptor("$expr$", pattern);
+          if (GUAVA_OPTIONAL.equals(qName)) {
+            TypeConversionDescriptor descriptor =
+              new TypeConversionDescriptor(null, "java.util.Optional.ofNullable($val$.orElseGet($o$::get))") {
+                @Override
+                public PsiExpression replace(PsiExpression expression) {
+                  setStringToReplace("$val$.or(" +
+                                     GuavaOptionalConversionUtil.simplifyParameterPattern((PsiMethodCallExpression)expression)
+                                     + ")");
+                  return super.replace(expression);
+                }
+              };
+            if (to != null) {
+              descriptor.withConversionType(to);
+            }
+            return descriptor;
+          }
+          return GuavaSupplierConversionRule.GUAVA_SUPPLIER.equals(qName)
+                 ? new LambdaParametersTypeConversionDescriptor("$val$.or($other$)", "$val$.orElseGet($other$)")
+                 : new TypeConversionDescriptor("$val$.or($other$)", "$val$.orElse($other$)");
         }
         return null;
       }
-      else if (context.getParent() instanceof PsiMethodCallExpression) {
-        methodCallExpression = (PsiMethodCallExpression)context.getParent();
-      }
-      if (methodCallExpression == null) {
-        return null;
-      }
-      final PsiClass aClass = getParameterClass(method);
-      if (aClass != null) {
-        final String qName = aClass.getQualifiedName();
-        if (GUAVA_OPTIONAL.equals(qName)) {
-          TypeConversionDescriptor descriptor =
-            new TypeConversionDescriptor("$val$.or($other$)", "java.util.Optional.ofNullable($val$.orElseGet($other$::get))");
-          if (to != null) {
-            descriptor.withConversionType(to);
-          }
+      else if ("transform".equals(methodName)) {
+        final PsiMethodCallExpression methodCall = (PsiMethodCallExpression)(context.getParent());
+        final PsiExpression[] arguments = methodCall.getArgumentList().getExpressions();
+        if (arguments.length != 1) {
+          return null;
+        }
+        final PsiExpression functionArgument = arguments[0];
+        final TypeConversionDescriptor descriptor = new LambdaParametersTypeConversionDescriptor("$val$.transform($fun$)", "$val$.map($fun$)");
+        final PsiType typeParameter = GuavaConversionUtil.getFunctionReturnType(functionArgument);
+        if (typeParameter == null) {
           return descriptor;
         }
-        return GuavaSupplierConversionRule.GUAVA_SUPPLIER.equals(qName)
-               ? new LambdaParametersTypeConversionDescriptor("$val$.or($other$)", "$val$.orElseGet($other$)")
-               : new TypeConversionDescriptor("$val$.or($other$)", "$val$.orElse($other$)");
+        final String rawOptionalType = JAVA_OPTIONAL + "<" + typeParameter.getCanonicalText(false) + ">";
+        return descriptor.withConversionType(JavaPsiFacade.getElementFactory(method.getProject()).createTypeFromText(rawOptionalType, context));
       }
       return null;
     }
-    if (!(context instanceof PsiMethodCallExpression)) {
-      return null;
-    }
     final PsiClass aClass = method.getContainingClass();
-    if (aClass == null || !GuavaFluentIterableConversionRule.FLUENT_ITERABLE.equals(aClass.getQualifiedName())) {
+    if (aClass == null || !(GuavaFluentIterableConversionRule.FLUENT_ITERABLE.equals(aClass.getQualifiedName()) ||
+                            GUAVA_OPTIONAL.equals(aClass.getQualifiedName()))) {
       return null;
     }
     return GuavaFluentIterableConversionRule.buildCompoundDescriptor((PsiMethodCallExpression) context, to, labeler);
   }
 
+  @Override
+  protected boolean isValidMethodQualifierToConvert(PsiClass aClass) {
+    return super.isValidMethodQualifierToConvert(aClass) ||
+           (aClass != null && GuavaFluentIterableConversionRule.FLUENT_ITERABLE.equals(aClass.getQualifiedName()));
+  }
+
   @Nullable
   @Override
   protected TypeConversionDescriptorBase findConversionForVariableReference(@NotNull PsiReferenceExpression referenceExpression,
-                                                                            @NotNull PsiVariable psiVariable) {
+                                                                            @NotNull PsiVariable psiVariable,
+                                                                            @Nullable PsiExpression context) {
+    if (GuavaOptionalConversionUtil.isOptionalOrContext(context)) {
+      return new TypeConversionDescriptor("$o$", "com.google.common.base." + OPTIONAL_CONVERTOR_PATTERN);
+    }
     return new TypeConversionDescriptor("$o$", "$o$::get");
   }
 
@@ -132,7 +157,6 @@ public class GuavaOptionalConversionRule extends BaseGuavaTypeConversionRule {
     descriptorsMap.put("orNull", new TypeConversionDescriptor("$val$.orNull()", "$val$.orElse(null)"));
     descriptorsMap.put("asSet", new TypeConversionDescriptor("$val$.asSet()",
                                                              "$val$.isPresent() ? java.util.Collections.singleton($val$.get()) : java.util.Collections.emptySet()"));
-    descriptorsMap.put("transform", new TypeConversionDescriptor("$val$.transform($fun$)", "$val$.map($fun$)"));
   }
 
   @NotNull
diff --git a/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaOptionalConversionUtil.java b/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/guava/GuavaOptionalConversionUtil.java
new file mode 100644 (file)
index 0000000..828e58b
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.refactoring.typeMigration.rules.guava;
+
+import com.intellij.openapi.fileTypes.StdFileTypes;
+import com.intellij.psi.*;
+import com.intellij.psi.util.PsiMatcherExpression;
+import com.intellij.refactoring.typeMigration.TypeConversionDescriptor;
+import com.intellij.structuralsearch.MatchOptions;
+import com.intellij.structuralsearch.MatchResult;
+import com.intellij.structuralsearch.Matcher;
+import com.intellij.structuralsearch.plugin.replace.impl.Replacer;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.List;
+
+/**
+ * @author Dmitry Batkovich
+ */
+public class GuavaOptionalConversionUtil {
+  static boolean isOptionalOrContext(@Nullable PsiExpression context) {
+    if (context == null) return false;
+    final PsiElement parent = context.getParent();
+    if (parent == null) return false;
+    final PsiElement maybeMethodCall = parent.getParent();
+    if (!(maybeMethodCall instanceof PsiMethodCallExpression)) return false;
+    final PsiMethodCallExpression methodCall = (PsiMethodCallExpression)maybeMethodCall;
+    final int argumentLength = methodCall.getArgumentList().getExpressions().length;
+    if (argumentLength != 1) return false;
+    final PsiMethod resolvedMethod = methodCall.resolveMethod();
+    if (resolvedMethod == null || !"or".equals(resolvedMethod.getName())) return false;
+    final PsiClass aClass = resolvedMethod.getContainingClass();
+    return aClass != null && GuavaOptionalConversionRule.GUAVA_OPTIONAL.equals(aClass.getQualifiedName());
+  }
+
+  static String simplifyParameterPattern(PsiMethodCallExpression methodCall) {
+    final PsiExpressionList argumentList = methodCall.getArgumentList();
+    final PsiExpression[] expressions = argumentList.getExpressions();
+    if (expressions.length == 1) {
+      final PsiExpression expression = expressions[0];
+      Matcher matcher = new Matcher(methodCall.getProject());
+      final MatchOptions options = new MatchOptions();
+      options.setFileType(StdFileTypes.JAVA);
+      final List<MatchResult> results =
+        matcher.testFindMatches(expression.getText(), GuavaOptionalConversionRule.OPTIONAL_CONVERTOR_PATTERN, options, false);
+      if (!results.isEmpty()) {
+        final MatchResult result = results.get(0);
+        if (result.getStart() == 0 && result.getEnd() == -1) {
+          return GuavaOptionalConversionRule.OPTIONAL_CONVERTOR_PATTERN;
+        }
+      }
+    }
+    return "$o$";
+  }
+}
index 3fdb2e50123dabee34360c3d543c5d2e5ef7cb31..6848ccd8d61a93bf35cf19496246597a4db81a67 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.intellij.refactoring.typeMigration.rules.guava;
 
+import com.intellij.psi.PsiExpression;
 import com.intellij.psi.PsiReferenceExpression;
 import com.intellij.psi.PsiVariable;
 import com.intellij.refactoring.typeMigration.TypeConversionDescriptor;
@@ -39,7 +40,7 @@ public class GuavaPredicateConversionRule extends BaseGuavaTypeConversionRule {
   @Nullable
   @Override
   protected TypeConversionDescriptorBase findConversionForVariableReference(@NotNull PsiReferenceExpression referenceExpression,
-                                                                            @NotNull PsiVariable psiVariable) {
+                                                                            @NotNull PsiVariable psiVariable, PsiExpression context) {
     return new TypeConversionDescriptor("$p$", "$p$::test");
   }
 
index dc9df00e32506f6d2d17219ade2a9d2a055d60e7..ed1b3efa448ce21bc5708b3af805b92fec9168c3 100644 (file)
  */
 package com.intellij.refactoring.typeMigration.rules.guava;
 
+import com.intellij.psi.PsiExpression;
+import com.intellij.psi.PsiReferenceExpression;
+import com.intellij.psi.PsiVariable;
 import com.intellij.refactoring.typeMigration.TypeConversionDescriptor;
 import com.intellij.refactoring.typeMigration.TypeConversionDescriptorBase;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import java.util.Map;
 
@@ -26,12 +30,20 @@ import java.util.Map;
  */
 public class GuavaSupplierConversionRule extends BaseGuavaTypeConversionRule {
   public final static String GUAVA_SUPPLIER = "com.google.common.base.Supplier";
+  public static final String JAVA_SUPPLIER = "java.util.function.Supplier";
 
   @Override
   protected void fillSimpleDescriptors(Map<String, TypeConversionDescriptorBase> descriptorsMap) {
     descriptorsMap.put("get", new TypeConversionDescriptor("$val$.get()", "$val$.get()"));
   }
 
+  @Nullable
+  @Override
+  protected TypeConversionDescriptorBase findConversionForVariableReference(@NotNull PsiReferenceExpression referenceExpression,
+                                                                            @NotNull PsiVariable psiVariable, PsiExpression context) {
+    return new TypeConversionDescriptor("$f$", "$f$::get");
+  }
+
   @NotNull
   @Override
   public String ruleFromClass() {
@@ -41,6 +53,6 @@ public class GuavaSupplierConversionRule extends BaseGuavaTypeConversionRule {
   @NotNull
   @Override
   public String ruleToClass() {
-    return "java.util.function.Supplier";
+    return JAVA_SUPPLIER;
   }
 }
index 586be0b84ea28c37cfc953fbc5c7bfe73ef21ad8..b2f16c5c662e2122bb4ffb484e6a3d66f18cb3b1 100644 (file)
@@ -17,7 +17,10 @@ package com.intellij.refactoring.typeMigration.rules.guava;
 
 import com.intellij.codeInspection.AnonymousCanBeLambdaInspection;
 import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.util.Comparing;
 import com.intellij.psi.*;
+import com.intellij.psi.util.InheritanceUtil;
+import com.intellij.psi.util.PsiTypesUtil;
 import com.intellij.refactoring.typeMigration.TypeConversionDescriptor;
 import org.jetbrains.annotations.NonNls;
 
@@ -75,6 +78,17 @@ public class LambdaParametersTypeConversionDescriptor extends TypeConversionDesc
     else if (!(expression instanceof PsiFunctionalExpression)) {
       return addApplyReference(expression);
     }
+    else if (expression instanceof PsiMethodReferenceExpression) {
+      final PsiElement qualifier = ((PsiMethodReferenceExpression)expression).getQualifier();
+      PsiType qualifierType;
+      if (qualifier instanceof PsiExpression && (qualifierType = ((PsiExpression)qualifier).getType()) != null) {
+        final PsiClass qualifierClass = PsiTypesUtil.getPsiClass(qualifierType);
+        if (qualifierClass != null && (Comparing.equal(qualifierClass.getQualifiedName(), GuavaFunctionConversionRule.JAVA_UTIL_FUNCTION_FUNCTION) ||
+            Comparing.equal(qualifierClass.getQualifiedName(), GuavaOptionalConversionRule.JAVA_OPTIONAL) ||
+            Comparing.equal(qualifierClass.getQualifiedName(), GuavaSupplierConversionRule.JAVA_SUPPLIER)))
+        return (PsiExpression)expression.replace(qualifier);
+      }
+    }
     return expression;
   }
 }
index a12a4f578765192c4033eec20e7233b871876a83..3a3894b5e95696dfeaac470cfc93b453fcfd5383 100644 (file)
@@ -186,6 +186,26 @@ public class GuavaInspectionTest extends JavaCodeInsightFixtureTestCase {
     doTest();
   }
 
+  public void testOptionalTransform() {
+    doTest();
+  }
+
+  public void testOptionalTransform2() {
+    doTest();
+  }
+
+  public void testRemoveMethodReference() {
+    doTest();
+  }
+
+  public void testSimplifyOptionalComposition() {
+    doTest();
+  }
+
+  public void testMigrateArrays() {
+    doTest();
+  }
+
   private void doTestNoQuickFixes(final Class<? extends IntentionAction>... quickFixesClasses) {
     myFixture.configureByFile(getTestName(true) + ".java");
     myFixture.enableInspections(new GuavaInspection());
index ead8a4bcb6e64a5a4427d359b28d33270416ecb3..6b0576163b106b25fc793a668297f21e8635f21e 100644 (file)
@@ -866,6 +866,12 @@ public class TypeMigrationTest extends TypeMigrationTestBase {
                            myFactory.createTypeFromText("java.lang.Integer", null));
   }
 
+  public void testT140() {
+    doTestFirstParamType("meth",
+                         myFactory.createTypeFromText("java.util.List<U>", null),
+                         myFactory.createTypeFromText("java.util.Set<U>", null));
+  }
+
   private void doTestForeachParameter(final PsiType rootType, final PsiType migrationType) {
     start(new RulesProvider() {
       @Override
diff --git