Merge branch 'master' into changeSignature
authorMaxim Medvedev <maxim.medvedev@jetbrains.com>
Wed, 28 Apr 2010 12:00:32 +0000 (16:00 +0400)
committerMaxim Medvedev <maxim.medvedev@jetbrains.com>
Wed, 28 Apr 2010 12:00:32 +0000 (16:00 +0400)
Conflicts:
java/java-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureProcessor.java

356 files changed:
RegExpSupport/RegExpSupport.iml
RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpBackrefImpl.java
RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpPropertyImpl.java
RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpPyNamedGroupRefImpl.java
RegExpSupport/test/test/BaseParseTestcase.java
build/scripts/common_tests.gant
java/debugger/impl/src/com/intellij/debugger/ui/DebuggerSessionTab.java
java/execution/impl/src/com/intellij/execution/applet/AppletConfiguration.java
java/java-impl/src/com/intellij/codeInsight/completion/AllClassesGetter.java
java/java-impl/src/com/intellij/codeInsight/completion/CastingLookupElementDecorator.java
java/java-impl/src/com/intellij/codeInsight/completion/JavaChainLookupElement.java
java/java-impl/src/com/intellij/codeInsight/completion/JavaClassNameInsertHandler.java [new file with mode: 0644]
java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionUtil.java
java/java-impl/src/com/intellij/codeInsight/completion/JavaDocCompletionContributor.java
java/java-impl/src/com/intellij/codeInsight/completion/JavaSmartCompletionContributor.java
java/java-impl/src/com/intellij/codeInsight/completion/PreferSimpleWeigher.java
java/java-impl/src/com/intellij/codeInsight/lookup/PsiTypeLookupItem.java
java/java-impl/src/com/intellij/psi/AbstractQualifiedReference.java
java/java-impl/src/com/intellij/psi/formatter/java/AbstractJavaBlock.java
java/java-impl/src/com/intellij/psi/formatter/java/BlockContainingJavaBlock.java
java/java-impl/src/com/intellij/psi/formatter/java/FormattingAstUtil.java
java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java
java/java-impl/src/com/intellij/psi/formatter/java/spacing/JavaBraceSpacingProcessor.java [new file with mode: 0644]
java/java-impl/src/com/intellij/psi/formatter/java/wrap/impl/JavaChildWrapArranger.java
java/java-impl/src/com/intellij/psi/impl/PsiClassImplUtil.java
java/java-impl/src/com/intellij/psi/impl/PsiImplUtil.java
java/java-impl/src/com/intellij/psi/impl/compiled/ClsJavaCodeReferenceElementImpl.java
java/java-impl/src/com/intellij/psi/impl/compiled/ClsReferenceExpressionImpl.java
java/java-impl/src/com/intellij/psi/impl/compiled/ClsTypeParameterReferenceImpl.java
java/java-impl/src/com/intellij/psi/impl/light/LightClassReference.java
java/java-impl/src/com/intellij/psi/impl/light/LightMemberReference.java
java/java-impl/src/com/intellij/psi/impl/light/LightPackageReference.java
java/java-impl/src/com/intellij/psi/impl/source/PsiEnumConstantImpl.java
java/java-impl/src/com/intellij/psi/impl/source/PsiImportStaticReferenceElementImpl.java
java/java-impl/src/com/intellij/psi/impl/source/PsiJavaCodeReferenceElementImpl.java
java/java-impl/src/com/intellij/psi/impl/source/PsiLabelReference.java
java/java-impl/src/com/intellij/psi/impl/source/javadoc/PsiDocMethodOrFieldRef.java
java/java-impl/src/com/intellij/psi/impl/source/javadoc/PsiDocParamRef.java
java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/JavaClassReference.java
java/java-impl/src/com/intellij/psi/impl/source/tree/java/PsiNameValuePairImpl.java
java/java-impl/src/com/intellij/psi/impl/source/tree/java/PsiNewExpressionImpl.java
java/java-impl/src/com/intellij/psi/impl/source/tree/java/PsiReferenceExpressionImpl.java
java/java-impl/src/com/intellij/psi/util/proximity/JavaInheritanceWeigher.java
java/java-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureProcessor.java
java/java-impl/src/com/intellij/refactoring/convertToInstanceMethod/ConvertToInstanceMethodProcessor.java
java/java-impl/src/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsProcessor.java
java/java-impl/src/com/intellij/refactoring/extractclass/ExtractClassProcessor.java
java/java-impl/src/com/intellij/refactoring/extractclass/usageInfo/ReplaceInstanceVariableAccess.java
java/java-impl/src/com/intellij/refactoring/extractclass/usageInfo/ReplaceInstanceVariableAssignment.java
java/java-impl/src/com/intellij/refactoring/extractclass/usageInfo/ReplaceInstanceVariableIncrementDecrement.java
java/java-impl/src/com/intellij/refactoring/inheritanceToDelegation/InheritanceToDelegationProcessor.java
java/java-impl/src/com/intellij/refactoring/inline/InlineConstantFieldProcessor.java
java/java-impl/src/com/intellij/refactoring/inline/InlineLocalHandler.java
java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java
java/java-impl/src/com/intellij/refactoring/inline/InlineParameterExpressionProcessor.java
java/java-impl/src/com/intellij/refactoring/inline/InlineToAnonymousClassProcessor.java
java/java-impl/src/com/intellij/refactoring/inlineSuperClass/InlineSuperClassRefactoringProcessor.java
java/java-impl/src/com/intellij/refactoring/introduceField/ElementToWorkOn.java
java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterProcessor.java
java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java
java/java-impl/src/com/intellij/refactoring/introduceparameterobject/IntroduceParameterObjectProcessor.java
java/java-impl/src/com/intellij/refactoring/makeStatic/MakeMethodOrClassStaticProcessor.java
java/java-impl/src/com/intellij/refactoring/memberPushDown/PushDownProcessor.java
java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassToInnerProcessor.java
java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesProcessor.java
java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveDirectoryWithClassesProcessor.java
java/java-impl/src/com/intellij/refactoring/move/moveInner/MoveInnerProcessor.java
java/java-impl/src/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodProcessor.java
java/java-impl/src/com/intellij/refactoring/move/moveMembers/MoveMembersProcessor.java
java/java-impl/src/com/intellij/refactoring/removemiddleman/RemoveMiddlemanProcessor.java
java/java-impl/src/com/intellij/refactoring/replaceConstructorWithBuilder/ReplaceConstructorWithBuilderProcessor.java
java/java-impl/src/com/intellij/refactoring/replaceConstructorWithFactory/ReplaceConstructorWithFactoryProcessor.java
java/java-impl/src/com/intellij/refactoring/wrapreturnvalue/WrapReturnValueProcessor.java
java/java-tests/testData/refactoring/extractClass/multipleGetters/after/Extracted.java [deleted file]
java/java-tests/testData/refactoring/extractClass/multipleGetters/after/Test.java
java/java-tests/testData/refactoring/extractClass/publicFieldDelegation/after/Test.java
java/java-tests/testData/refactoring/inlineMethod/MethodCallInOtherAnonymousOrInner.java [new file with mode: 0644]
java/java-tests/testData/refactoring/inlineMethod/MethodCallInOtherAnonymousOrInner.java.after [new file with mode: 0644]
java/java-tests/testData/refactoring/replaceConstructorWithBuilder/constructorChain/after/Builder.java
java/java-tests/testSrc/com/intellij/JavaTestUtil.java
java/java-tests/testSrc/com/intellij/psi/formatter/AbstractJavaFormattingTest.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/psi/formatter/JavaFormatterAlignmentTest.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/psi/formatter/JavaFormatterNewLineTest.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/psi/formatter/JavaFormatterTest.java
java/java-tests/testSrc/com/intellij/psi/formatter/JavaFormattingBlankLinesTest.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/psi/formatter/JavaFormattingBracesTest.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/psi/formatter/JavaFormattingIndentationTest.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/refactoring/ExtractClassTest.java
java/java-tests/testSrc/com/intellij/refactoring/PushDownTest.java
java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java
java/openapi/src/com/intellij/patterns/PsiClassPattern.java
native/fsNotifier/linux/fsnotifier64 [new file with mode: 0755]
native/fsNotifier/linux/main.c
native/fsNotifier/linux/make.sh
platform/icons/src/mac/tree_white_down_arrow.png [new file with mode: 0644]
platform/icons/src/mac/tree_white_right_arrow.png [new file with mode: 0644]
platform/lang-api/src/com/intellij/analysis/AnalysisScope.java
platform/lang-api/src/com/intellij/codeInsight/completion/PrioritizedLookupElement.java
platform/lang-api/src/com/intellij/execution/ui/RunnerLayoutUi.java
platform/lang-api/src/com/intellij/psi/PsiReference.java
platform/lang-api/src/com/intellij/psi/PsiReferenceBase.java
platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettings.java
platform/lang-api/src/com/intellij/psi/impl/ElementBase.java
platform/lang-impl/src/com/intellij/analysis/BaseAnalysisAction.java
platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionLookupArranger.java
platform/lang-impl/src/com/intellij/codeInsight/completion/PriorityWeigher.java
platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupManagerImpl.java
platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java
platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java
platform/lang-impl/src/com/intellij/execution/ui/layout/impl/GridCellImpl.java
platform/lang-impl/src/com/intellij/execution/ui/layout/impl/GridImpl.java
platform/lang-impl/src/com/intellij/execution/ui/layout/impl/RunnerContentUi.java
platform/lang-impl/src/com/intellij/execution/ui/layout/impl/RunnerLayoutUiImpl.java
platform/lang-impl/src/com/intellij/formatting/CompositeBlockWrapper.java
platform/lang-impl/src/com/intellij/formatting/IndentData.java
platform/lang-impl/src/com/intellij/ide/actions/GotoFileAction.java
platform/lang-impl/src/com/intellij/ide/fileTemplates/impl/FileTemplateManagerImpl.java
platform/lang-impl/src/com/intellij/ide/hierarchy/HierarchyBrowserBase.java
platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java
platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewTree.java
platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/AbstractPsiBasedNode.java
platform/lang-impl/src/com/intellij/ide/structureView/newStructureView/StructureViewComponent.java
platform/lang-impl/src/com/intellij/ide/todo/TodoPanel.java
platform/lang-impl/src/com/intellij/openapi/paths/PsiDynaReference.java
platform/lang-impl/src/com/intellij/packageDependencies/actions/BackwardDependenciesAction.java
platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/PsiMultiReference.java
platform/lang-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FileReference.java
platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java
platform/lang-impl/src/com/intellij/refactoring/rename/RenameProcessor.java
platform/lang-impl/src/com/intellij/refactoring/ui/ConflictsDialog.java
platform/lang-impl/src/com/intellij/ui/DeferredIconImpl.java
platform/lvcs-impl/lvcs-impl.iml
platform/lvcs-impl/src/com/intellij/history/integration/patches/PatchCreator.java
platform/lvcs-impl/testSrc/com/intellij/historyIntegrTests/IntegrationTestCase.java
platform/platform-api/src/com/intellij/ide/DataManager.java
platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java
platform/platform-api/src/com/intellij/openapi/actionSystem/ActionToolbar.java
platform/platform-api/src/com/intellij/openapi/fileChooser/MacFileChooserDialog.java [new file with mode: 0644]
platform/platform-api/src/com/intellij/openapi/ui/Messages.java
platform/platform-api/src/com/intellij/openapi/ui/SimpleToolWindowPanel.java
platform/platform-api/src/com/intellij/openapi/util/Iconable.java
platform/platform-api/src/com/intellij/ui/ColoredTreeCellRenderer.java
platform/platform-api/src/com/intellij/ui/HighlightableCellRenderer.java
platform/platform-api/src/com/intellij/ui/switcher/ApplySwitchAction.java [new file with mode: 0644]
platform/platform-api/src/com/intellij/ui/switcher/QuickAccessProvider.java [new file with mode: 0644]
platform/platform-api/src/com/intellij/ui/switcher/QuickActionManager.java [new file with mode: 0644]
platform/platform-api/src/com/intellij/ui/switcher/QuickActionProvider.java [new file with mode: 0644]
platform/platform-api/src/com/intellij/ui/switcher/SwitchAction.java [new file with mode: 0644]
platform/platform-api/src/com/intellij/ui/switcher/SwitchManager.java [new file with mode: 0644]
platform/platform-api/src/com/intellij/ui/switcher/SwitchProvider.java [new file with mode: 0644]
platform/platform-api/src/com/intellij/ui/switcher/SwitchTarget.java [new file with mode: 0644]
platform/platform-api/src/com/intellij/ui/switcher/SwitchingSession.java [new file with mode: 0644]
platform/platform-api/src/com/intellij/ui/tabs/JBTabs.java
platform/platform-api/src/com/intellij/ui/tabs/JBTabsPresentation.java
platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.java
platform/platform-api/src/com/intellij/ui/treeStructure/Tree.java
platform/platform-api/src/com/intellij/util/IconUtil.java
platform/platform-api/src/com/intellij/util/concurrency/QueueProcessor.java [new file with mode: 0644]
platform/platform-api/src/com/intellij/util/concurrency/WorkerThread.java
platform/platform-impl/src/com/intellij/execution/process/ColoredProcessHandler.java
platform/platform-impl/src/com/intellij/ide/impl/DataManagerImpl.java
platform/platform-impl/src/com/intellij/idea/RareLogger.java [new file with mode: 0644]
platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionButton.java
platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionToolbarImpl.java
platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/Utils.java
platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationInfoImpl.java
platform/platform-impl/src/com/intellij/openapi/fileChooser/impl/FileChooserFactoryImpl.java
platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/EditorTabbedContainer.java
platform/platform-impl/src/com/intellij/openapi/keymap/impl/ui/KeyboardShortcutDialog.java
platform/platform-impl/src/com/intellij/openapi/options/newEditor/OptionsTree.java
platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/FSRecords.java
platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ComboContentLayout.java
platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ContentLayout.java
platform/platform-impl/src/com/intellij/openapi/wm/impl/content/TabContentLayout.java
platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ToolWindowContentUi.java
platform/platform-impl/src/com/intellij/ui/content/impl/ContentManagerImpl.java
platform/platform-impl/src/com/intellij/ui/mac/MacFileChooserDialogImpl.java [moved from platform/platform-impl/src/com/intellij/ui/mac/MacFileChooserDialog.java with 55% similarity]
platform/platform-impl/src/com/intellij/ui/mac/foundation/Foundation.java
platform/platform-resources-en/src/messages/ActionsBundle.properties
platform/platform-resources-en/src/misc/registry.properties
platform/platform-resources-en/src/tips/ColorFiles.html [moved from resources-en/src/tips/ColorFiles.html with 100% similarity]
platform/platform-resources-en/src/tips/CopyWithNoSelection.html [moved from resources-en/src/tips/CopyWithNoSelection.html with 100% similarity]
platform/platform-resources-en/src/tips/Spellchecker.html [moved from resources-en/src/tips/Spellchecker.html with 100% similarity]
platform/platform-resources-en/src/tips/SpellcheckerDictionaries.html [moved from resources-en/src/tips/SpellcheckerDictionaries.html with 100% similarity]
platform/platform-resources-en/src/tips/VcsQuickList.html [moved from resources-en/src/tips/VcsQuickList.html with 100% similarity]
platform/platform-resources-en/src/tips/moveFileToChangelist.html [moved from resources-en/src/tips/moveFileToChangelist.html with 100% similarity]
platform/platform-resources/src/META-INF/PlatformExtensions.xml
platform/platform-resources/src/META-INF/PlatformLangPlugin.xml
platform/platform-resources/src/META-INF/PlatformLangXmlPlugin.xml
platform/platform-resources/src/componentSets/UICore.xml
platform/platform-resources/src/idea/Keymap_Default.xml
platform/platform-resources/src/idea/Keymap_Eclipse.xml
platform/platform-resources/src/idea/Keymap_Emacs.xml
platform/platform-resources/src/idea/Keymap_Mac.xml
platform/platform-resources/src/idea/Keymap_MacClassic.xml
platform/platform-resources/src/idea/PlatformActions.xml
platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java
platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java
platform/testFramework/testFramework.iml
platform/util/src/com/intellij/openapi/util/JDOMUtil.java
platform/util/src/com/intellij/util/concurrency/Semaphore.java
platform/util/src/com/intellij/util/ui/UIUtil.java
platform/vcs-api/src/com/intellij/openapi/diff/impl/patch/IdeaTextPatchBuilder.java [new file with mode: 0644]
platform/vcs-api/src/com/intellij/openapi/diff/impl/patch/TextPatchBuilder.java
platform/vcs-api/src/com/intellij/openapi/vcs/AbstractVcs.java
platform/vcs-api/src/com/intellij/openapi/vcs/CollectionSplitter.java [new file with mode: 0644]
platform/vcs-api/src/com/intellij/openapi/vcs/ProjectLevelVcsManager.java
platform/vcs-api/src/com/intellij/openapi/vcs/VcsOutgoingChangesProvider.java
platform/vcs-api/src/com/intellij/openapi/vcs/changes/SortByVcsRoots.java [new file with mode: 0644]
platform/vcs-api/src/com/intellij/openapi/vcs/changes/TextRevisionNumber.java [new file with mode: 0644]
platform/vcs-api/src/com/intellij/openapi/vcs/checkin/CheckinHandler.java
platform/vcs-api/src/com/intellij/openapi/vcs/update/FileGroup.java
platform/vcs-api/src/com/intellij/openapi/vcs/update/UpdatedFiles.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/RevertCommittedStuffAbstractAction.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangeListRenderer.java [new file with mode: 0644]
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesTreeBrowser.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchCommitExecutor.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/DefaultPatchBaseVersionProvider.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChange.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowser.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTreeList.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java
platform/vcs-impl/src/com/intellij/openapi/vcs/impl/LineStatusTrackerManager.java
platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java
platform/xdebugger-api/src/com/intellij/xdebugger/XDebugProcessStarter.java
platform/xdebugger-api/src/com/intellij/xdebugger/XDebuggerManager.java
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerManagerImpl.java
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/actions/XWatchesTreeActionBase.java
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerSessionTabBase.java [moved from platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerLogConsoleManagerBase.java with 88% similarity]
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebugSessionTab.java
plugins/InspectionGadgets/src/com/siyeh/ig/maturity/ObsoleteCollectionInspection.java
plugins/InspectionGadgets/testsrc/com/IGInspectionTestCase.java
plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/util/StringLiteralReference.java
plugins/ant/src/com/intellij/lang/ant/config/explorer/AntExplorer.java
plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntEntityReference.java
plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntGenericReference.java
plugins/ant/src/com/intellij/lang/ant/psi/impl/reference/AntMacroDefParameterReference.java
plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/CvsCheckinHandlerFactory.java
plugins/git4idea/src/git4idea/GitUtil.java
plugins/git4idea/src/git4idea/GitVcs.java
plugins/git4idea/src/git4idea/changes/GitOutgoingChangesProvider.java
plugins/git4idea/src/git4idea/history/browser/ChangesFilter.java
plugins/git4idea/src/git4idea/history/browser/FictiveTableCellRenderer.java
plugins/git4idea/src/git4idea/history/browser/GitLogTree.java
plugins/git4idea/src/git4idea/history/browser/GitProjectLogManager.java
plugins/git4idea/src/git4idea/history/browser/GitTreeController.java
plugins/git4idea/src/git4idea/history/browser/GitTreeFiltering.java
plugins/git4idea/src/git4idea/history/browser/LowLevelAccess.java
plugins/git4idea/src/git4idea/history/browser/LowLevelAccessImpl.java
plugins/groovy/grape/src/META-INF/plugin.xml
plugins/groovy/grape/src/org/jetbrains/plugins/groovy/grape/GrabDependencies.java
plugins/groovy/rt/src/org/jetbrains/groovy/compiler/rt/GroovyCompilerWrapper.java
plugins/groovy/src/META-INF/plugin.xml
plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/generator/GroovyToJavaGenerator.java
plugins/groovy/src/org/jetbrains/plugins/groovy/gant/GantTargetReference.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyClassNameInsertHandler.java [new file with mode: 0644]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/editor/GroovyImportOptimizer.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/groovydoc/psi/impl/GrDocMemberReferenceImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/groovydoc/psi/impl/GrDocParameterReferenceImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/lexer/_GroovyLexer.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/lexer/groovy.flex
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/auxiliary/GrLabelReference.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/auxiliary/annotation/GrAnnotationNameValuePairImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrConstructorInvocationImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/arguments/GrArgumentLabelImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/types/GrCodeReferenceElementImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/move/MoveGroovyScriptProcessor.java
plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyClassNameCompletionTest.java [new file with mode: 0644]
plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GeneratorTest.java
plugins/groovy/test/org/jetbrains/plugins/groovy/lang/parser/ExpressionsParsingTest.groovy
plugins/groovy/testdata/groovy/completion/classNameCompletion/InComment.groovy [new file with mode: 0644]
plugins/groovy/testdata/groovy/completion/classNameCompletion/InComment_after.groovy [new file with mode: 0644]
plugins/groovy/testdata/groovy/completion/classNameCompletion/InFieldDeclaration.groovy [new file with mode: 0644]
plugins/groovy/testdata/groovy/completion/classNameCompletion/InFieldDeclaration_after.groovy [new file with mode: 0644]
plugins/groovy/testdata/groovy/completion/classNameCompletion/InImport.groovy [new file with mode: 0644]
plugins/groovy/testdata/groovy/completion/classNameCompletion/InImport_after.groovy [new file with mode: 0644]
plugins/groovy/testdata/groovy/completion/classNameCompletion/InParameter.groovy [new file with mode: 0644]
plugins/groovy/testdata/groovy/completion/classNameCompletion/InParameter_after.groovy [new file with mode: 0644]
plugins/groovy/testdata/groovy/completion/classNameCompletion/InTypeElementPlace.groovy [new file with mode: 0644]
plugins/groovy/testdata/groovy/completion/classNameCompletion/InTypeElementPlace_after.groovy [new file with mode: 0644]
plugins/groovy/testdata/groovy/completion/classNameCompletion/WhenClassExistsInSamePackage.groovy [new file with mode: 0644]
plugins/groovy/testdata/groovy/completion/classNameCompletion/WhenClassExistsInSamePackage_after.groovy [new file with mode: 0644]
plugins/groovy/testdata/groovy/completion/classNameCompletion/WhenImportExists.groovy [new file with mode: 0644]
plugins/groovy/testdata/groovy/completion/classNameCompletion/WhenImportExists_after.groovy [new file with mode: 0644]
plugins/groovy/testdata/groovy/stubGenerator/checkedExceptionInConstructorDelegate.test [new file with mode: 0644]
plugins/groovy/testdata/groovy/stubGenerator/inaccessiblePropertyType.test [new file with mode: 0644]
plugins/groovy/testdata/groovy/stubGenerator/superInvocation1.test
plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/references/MavenPsiReference.java
plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenProjectsNavigatorPanel.java
plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenProjectsStructure.java
plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenArtifactNode.java
plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenArtifactState.java [new file with mode: 0644]
plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProject.java
plugins/maven/src/main/java/org/jetbrains/idea/maven/project/actions/ReimportAction.java
plugins/maven/src/main/java/org/jetbrains/idea/maven/project/actions/RemoveManagedFilesAction.java
plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/actions/MavenAction.java
plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/actions/MavenActionUtil.java
plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/actions/MavenToggleAction.java
plugins/properties/src/com/intellij/lang/properties/ResourceBundleReference.java
plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic
plugins/spellchecker/testData/inspection/propertiesWithMistakes/test.properties
plugins/svn4idea/src/org/jetbrains/idea/svn/SvnBundle.properties
plugins/svn4idea/src/org/jetbrains/idea/svn/SvnVcs.java
plugins/svn4idea/src/org/jetbrains/idea/svn/actions/ChangeListsMergerFactory.java
plugins/svn4idea/src/org/jetbrains/idea/svn/actions/ChangeSetMergerFactory.java
plugins/svn4idea/src/org/jetbrains/idea/svn/actions/RecordOnlyMergerFactory.java
plugins/svn4idea/src/org/jetbrains/idea/svn/actions/SelectBranchPopup.java
plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/BasePageEngine.java [new file with mode: 0644]
plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/BranchMerger.java [new file with mode: 0644]
plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/CopiesPanel.java
plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/PageEngine.java [new file with mode: 0644]
plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/PagedListWithActions.java [new file with mode: 0644]
plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/QuantitySelection.java [new file with mode: 0644]
plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/SelectionManipulation.java [new file with mode: 0644]
plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/SelectionResult.java [new file with mode: 0644]
plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/SvnChangeListsPageEngine.java [new file with mode: 0644]
plugins/svn4idea/src/org/jetbrains/idea/svn/dialogs/ToBeMergedDialog.java [new file with mode: 0644]
plugins/svn4idea/src/org/jetbrains/idea/svn/history/FirstInBranch.java
plugins/svn4idea/src/org/jetbrains/idea/svn/history/RootsAndBranches.java
plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnChangeList.java
plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnMergeSourceDetails.java
plugins/svn4idea/src/org/jetbrains/idea/svn/integrate/IMerger.java [new file with mode: 0644]
plugins/svn4idea/src/org/jetbrains/idea/svn/integrate/Merger.java
plugins/svn4idea/src/org/jetbrains/idea/svn/integrate/MergerFactory.java
plugins/svn4idea/src/org/jetbrains/idea/svn/integrate/ResolveWorker.java
plugins/svn4idea/src/org/jetbrains/idea/svn/integrate/SvnIntegrateChangesActionPerformer.java
plugins/svn4idea/src/org/jetbrains/idea/svn/integrate/SvnIntegrateChangesTask.java
plugins/svn4idea/src/org/jetbrains/idea/svn/mergeinfo/BranchInfo.java
plugins/svn4idea/src/org/jetbrains/idea/svn/mergeinfo/SvnMergeInfoCache.java
plugins/svn4idea/src/org/jetbrains/idea/svn/update/AbstractSvnUpdateIntegrateEnvironment.java
plugins/svn4idea/src/org/jetbrains/idea/svn/update/UpdateEventHandler.java
plugins/ui-designer/src/com/intellij/uiDesigner/binding/ReferenceInForm.java
plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/psi/impl/ReferenceBase.java
plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/psi/impl/XPathVariableReferenceImpl.java
plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/impl/references/ExternalResourceReference.java
plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/impl/references/SelfReference.java
plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/impl/references/SimpleAttributeReference.java
resources/src/META-INF/IdeaPlugin.xml
resources/src/idea/JBuilderKeymap.xml
xml/dom-impl/src/com/intellij/util/xml/impl/GenericDomValueReference.java
xml/impl/src/com/intellij/application/options/editor/WebEditorOptions.java
xml/impl/src/com/intellij/application/options/editor/WebEditorOptionsProvider.java
xml/impl/src/com/intellij/codeInsight/daemon/impl/analysis/encoding/XmlEncodingReference.java
xml/impl/src/com/intellij/lang/xml/XmlLiteralEscaper.java
xml/impl/src/com/intellij/psi/formatter/xml/XmlTagBlock.java
xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/BasicAttributeValueReference.java
xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/DtdReferencesProvider.java
xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/SchemaReferencesProvider.java
xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/URLReference.java
xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/XmlValueReference.java
xml/impl/src/com/intellij/psi/impl/source/xml/TagNameReference.java
xml/impl/src/com/intellij/psi/impl/source/xml/XmlAttributeImpl.java
xml/impl/src/com/intellij/psi/impl/source/xml/XmlDoctypeImpl.java
xml/impl/src/com/intellij/xml/util/AnchorReference.java

index b9b3142c9ce2c3c4c9283c02722ee9619737efd5..b04bc23eaecb8185ec9f3037481b5a49af29cfe9 100644 (file)
@@ -15,6 +15,7 @@
     <orderEntry type="module" module-name="xml" />
     <orderEntry type="module" module-name="testFramework" scope="TEST" />
     <orderEntry type="library" name="Jaxen" level="project" />
+    <orderEntry type="module" module-name="platform-ultimate" scope="TEST" />
   </component>
 </module>
 
index 63bad0e924d710e64fbe7d8d67751d24675f4f54..1e2b7b6b24420da859079db34982e71802f71aec 100644 (file)
@@ -80,6 +80,7 @@ public class RegExpBackrefImpl extends RegExpElementImpl implements RegExpBackre
                 return TextRange.from(0, getElement().getTextLength());
             }
 
+            @NotNull
             public String getCanonicalText() {
                 return getElement().getText();
             }
index 8f58881c7f96cb69f2aa5e40b139ad238e2f7ef2..de169fa939a911ea1460c3c27c7848da74035ea0 100644 (file)
@@ -102,6 +102,7 @@ public class RegExpPropertyImpl extends RegExpElementImpl implements RegExpPrope
             return RegExpPropertyImpl.this;
         }
 
+        @NotNull
         public String getCanonicalText() {
             return getRangeInElement().substring(getElement().getText());
         }
index 83944fa42102ca1cbffb173936aa0218103c8b97..a3f7e1dfd9f4cf1aed0817cf67e0e8439f510998 100644 (file)
@@ -87,6 +87,7 @@ public class RegExpPyNamedGroupRefImpl extends RegExpElementImpl implements RegE
         return RegExpPyNamedGroupRefImpl.this.resolve();
       }
 
+      @NotNull
       public String getCanonicalText() {
         return getRangeInElement().substring(getText());
       }
index b0670a2b6e1fd9152fb12155547fb11cddc82b65..a7f8cf4d00aac9c97556c0a4bf14d6c8ab5fa511 100644 (file)
@@ -20,6 +20,7 @@ import com.intellij.openapi.application.Result;
 import com.intellij.openapi.command.WriteCommandAction;
 import com.intellij.openapi.fileTypes.FileTypeManager;
 import com.intellij.openapi.project.Project;
+import com.intellij.testFramework.PlatformTestCase;
 import com.intellij.testFramework.fixtures.CodeInsightTestFixture;
 import com.intellij.testFramework.fixtures.IdeaProjectTestFixture;
 import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory;
@@ -32,6 +33,11 @@ import java.io.File;
 public abstract class BaseParseTestcase extends TestCase {
   protected CodeInsightTestFixture myFixture;
 
+  @SuppressWarnings({"JUnitTestCaseWithNonTrivialConstructors"})
+  public BaseParseTestcase() {
+    PlatformTestCase.initPlatformLangPrefix();
+  }
+
   protected void setUp() throws Exception {
     super.setUp();
     final IdeaTestFixtureFactory fixtureFactory = IdeaTestFixtureFactory.getFixtureFactory();
index d48f1f059e9938034814a708a7e54b01ff75af6b..c6eac41aceff4263ab495939d0d8bcb3d0793826 100644 (file)
@@ -25,6 +25,8 @@ target('default': 'The default target') {
     jvmarg (value: "-ea")
     jvmarg (value: "-Didea.home.path=$home")
     pass("idea.test.group")
+    pass("idea.test.patterns")
+    pass("idea.fast.only")
     pass("teamcity.tests.recentlyFailedTests.file")
     jvmarg (value: "-Didea.platform.prefix=Idea")
     jvmarg (value: "-Didea.home.path=$home")
index 3a5fb7b01e5f60cd1f3c982a99f1e5ae50f0d163..4a71d7f56ebd8e3906cda56a08e1fc79239cf349 100644 (file)
@@ -65,7 +65,7 @@ import com.intellij.unscramble.ThreadDumpPanel;
 import com.intellij.unscramble.ThreadState;
 import com.intellij.xdebugger.XDebuggerBundle;
 import com.intellij.xdebugger.impl.actions.XDebuggerActions;
-import com.intellij.xdebugger.impl.ui.DebuggerLogConsoleManagerBase;
+import com.intellij.xdebugger.impl.ui.DebuggerSessionTabBase;
 import com.intellij.xdebugger.impl.ui.XDebuggerUIConstants;
 import org.jetbrains.annotations.Nullable;
 
@@ -74,7 +74,7 @@ import javax.swing.tree.TreePath;
 import java.util.Collection;
 import java.util.List;
 
-public class DebuggerSessionTab extends DebuggerLogConsoleManagerBase implements Disposable {
+public class DebuggerSessionTab extends DebuggerSessionTabBase implements Disposable {
   private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.ui.DebuggerSessionTab");
 
   private static final Icon WATCH_RETURN_VALUES_ICON = IconLoader.getIcon("/debugger/watchLastReturnValue.png");
@@ -83,12 +83,9 @@ public class DebuggerSessionTab extends DebuggerLogConsoleManagerBase implements
   private final VariablesPanel myVariablesPanel;
   private final MainWatchPanel myWatchPanel;
 
-  private ExecutionConsole myConsole;
   private ProgramRunner myRunner;
   private volatile DebuggerSession myDebuggerSession;
 
-  private RunContentDescriptor myRunContentDescriptor;
-
   private final MyDebuggerStateManager myStateManager = new MyDebuggerStateManager();
 
   private final FramesPanel myFramesPanel;
@@ -420,13 +417,6 @@ public class DebuggerSessionTab extends DebuggerLogConsoleManagerBase implements
     }
   }
 
-  protected void toFront() {
-    if (!ApplicationManager.getApplication().isUnitTestMode()) {
-      ExecutionManager.getInstance(getProject()).getContentManager().toFrontRunContent(DefaultDebugExecutor.getDebugExecutorInstance(), myRunContentDescriptor);
-      ProjectUtil.focusProjectWindow(getProject(), Registry.is("debugger.mayBringFrameToFrontOnBreakpoint"));
-    }
-  }
-
   public String getSessionName() {
     return myConfiguration.getName();
   }
index 37b27e4cbef9522dabb37f3ac9f878d36e539df2..a1b83928a58d448bdcd0d779f3134fc9b4483f23 100644 (file)
@@ -44,6 +44,7 @@ import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
@@ -253,6 +254,12 @@ public class AppletConfiguration extends ModuleBasedConfiguration<JavaRunConfigu
       if (HTML_FILE_NAME == null || HTML_FILE_NAME.length() == 0) {
         throw new RuntimeConfigurationWarning(ExecutionBundle.message("html.file.not.specified.error.message"));
       }
+      try {
+        new URL(HTML_FILE_NAME);
+      }
+      catch (MalformedURLException ex) {
+        throw new RuntimeConfigurationWarning("URL " + HTML_FILE_NAME + " is not valid: " + ex.getLocalizedMessage());
+      }
     }
     else {
       getConfigurationModule().checkClassName(MAIN_CLASS_NAME, ExecutionBundle.message("no.applet.class.specified.error.message"));
index 8232e4ac8c301b3cd487462d724d6ea9818ef1d3..0c30d28b266b1e11aa9920665658004094dfcd66 100644 (file)
@@ -17,7 +17,7 @@ package com.intellij.codeInsight.completion;
 
 import com.intellij.codeInsight.CodeInsightUtilBase;
 import com.intellij.codeInsight.lookup.LookupElement;
-import com.intellij.lang.StdLanguages;
+import com.intellij.lang.LanguageExtension;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.Document;
@@ -31,7 +31,6 @@ import com.intellij.psi.*;
 import com.intellij.psi.filters.ElementFilter;
 import com.intellij.psi.search.GlobalSearchScope;
 import com.intellij.psi.search.searches.AllClassesSearch;
-import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.util.IncorrectOperationException;
 import com.intellij.util.Processor;
 import gnu.trove.THashSet;
@@ -67,28 +66,28 @@ public class AllClassesGetter {
       final PsiFile file = context.getFile();
       if (file.findElementAt(endOffset - 1) == null) return;
 
-      boolean checkReference = true;
-      if (file.getLanguage() == StdLanguages.JAVA) {
-        if (PsiTreeUtil.findElementOfClassAtOffset(file, endOffset - 1, PsiImportStatementBase.class, false) != null) {
-          checkReference = false;
-        } else {
-          final OffsetKey key = OffsetKey.create("endOffset", false);
-          context.getOffsetMap().addOffset(key, endOffset);
-          JavaPsiClassReferenceElement.JAVA_CLASS_INSERT_HANDLER.handleInsert(context, item);
-          final int newOffset = context.getOffsetMap().getOffset(key);
-          if (newOffset >= 0) {
-            endOffset = newOffset;
-          } else {
-            LOG.error(endOffset + " became invalid: " + context.getOffsetMap() + "; inserting " + qname);
-          }
-        }
+      final OffsetKey key = OffsetKey.create("endOffset", false);
+      context.getOffsetMap().addOffset(key, endOffset);
+      ClassNameInsertHandler handler = ClassNameInsertHandler.EP_NAME.forLanguage(file.getLanguage());
+      ClassNameInsertHandlerResult checkReference = ClassNameInsertHandlerResult.CHECK_FOR_CORRECT_REFERENCE;
+      if (handler != null) {
+        checkReference = handler.handleInsert(context, item);
+      }
+
+      final int newOffset = context.getOffsetMap().getOffset(key);
+      if (newOffset >= 0) {
+        endOffset = newOffset;
+      }
+      else {
+        LOG.error(endOffset + " became invalid: " + context.getOffsetMap() + "; inserting " + qname);
       }
 
       final RangeMarker toDelete = DefaultInsertHandler.insertSpace(endOffset, document);
       psiDocumentManager.commitAllDocuments();
       PsiReference psiReference = file.findReferenceAt(endOffset - 1);
-      boolean insertFqn = true;
-      if (checkReference && psiReference != null) {
+
+      boolean insertFqn=checkReference!=ClassNameInsertHandlerResult.REFERENCE_CORRECTED;
+      if (checkReference == ClassNameInsertHandlerResult.CHECK_FOR_CORRECT_REFERENCE && psiReference != null) {
         final PsiManager psiManager = file.getManager();
         if (psiManager.areElementsEquivalent(psiClass, DefaultInsertHandler.resolveReference(psiReference))) {
           insertFqn = false;
@@ -145,7 +144,7 @@ public class AllClassesGetter {
   }
 
   public void getClasses(final PsiElement context, final CompletionResultSet set, final int offset, final boolean filterByScope) {
-    if(context == null || !context.isValid()) return;
+    if (context == null || !context.isValid()) return;
 
     final String packagePrefix = getPackagePrefix(context, offset);
 
@@ -231,4 +230,16 @@ public class AllClassesGetter {
     });
   }
 
+
+  public interface ClassNameInsertHandler {
+    LanguageExtension<ClassNameInsertHandler> EP_NAME =
+      new LanguageExtension<ClassNameInsertHandler>("com.intellij.classNameInsertHandler");
+
+    ClassNameInsertHandlerResult handleInsert(InsertionContext context, JavaPsiClassReferenceElement item);
+  }
+
+  public enum ClassNameInsertHandlerResult {
+    INSERT_FQN, REFERENCE_CORRECTED, CHECK_FOR_CORRECT_REFERENCE
+  }
+
 }
index 5b9b54a039ef52e0ae1dc14e8e8ad6d354d84326..c9e5c70a7bfdca2d56e7680830b56d95cced1ad7 100644 (file)
@@ -78,4 +78,14 @@ public class CastingLookupElementDecorator extends LookupElementDecorator<Lookup
   static LookupElement createCastingElement(final LookupElement delegate, PsiType castTo) {
     return new CastingLookupElementDecorator(delegate, castTo);
   }
+  
+  public static @Nullable CastingLookupElementDecorator from(LookupElement element) {
+    if (element instanceof CastingLookupElementDecorator) return (CastingLookupElementDecorator)element;
+    else if (element instanceof LookupElementDecorator) {
+      element = ((LookupElementDecorator)element).getDelegate();
+      if (element instanceof CastingLookupElementDecorator) return (CastingLookupElementDecorator)element;
+    }
+    
+    return null;
+  }
 }
index 393820710bb04da3a75cb7fac713a05d4fab53a0..e2afa96bbdfedb82fb23c4d0ee423f10b24652a3 100644 (file)
@@ -122,7 +122,7 @@ public class JavaChainLookupElement extends LookupElementDecorator<LookupElement
 
   @NotNull
   private LookupElement getComparableQualifier() {
-    final CastingLookupElementDecorator casting = myQualifier.as(CastingLookupElementDecorator.class);
+    final CastingLookupElementDecorator casting = CastingLookupElementDecorator.from(myQualifier);
     return casting == null ? myQualifier : casting.getDelegate();
   }
 
diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaClassNameInsertHandler.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaClassNameInsertHandler.java
new file mode 100644 (file)
index 0000000..da96054
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2000-2010 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.lang.StdLanguages;
+import com.intellij.openapi.editor.Editor;
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.PsiImportStatementBase;
+import com.intellij.psi.util.PsiTreeUtil;
+
+/**
+* @author Maxim.Medvedev
+*/
+public class JavaClassNameInsertHandler implements AllClassesGetter.ClassNameInsertHandler {
+  public AllClassesGetter.ClassNameInsertHandlerResult handleInsert(InsertionContext context,
+                              JavaPsiClassReferenceElement item) {
+    Editor editor = context.getEditor();
+    PsiFile file = context.getFile();
+    int endOffset = editor.getCaretModel().getOffset();
+    if (file.getLanguage() == StdLanguages.JAVA) {
+      if (PsiTreeUtil.findElementOfClassAtOffset(file, endOffset - 1, PsiImportStatementBase.class, false) != null) {
+        return AllClassesGetter.ClassNameInsertHandlerResult.INSERT_FQN;
+      }
+      else {
+        JavaPsiClassReferenceElement.JAVA_CLASS_INSERT_HANDLER.handleInsert(context, item);
+      }
+    }
+    return AllClassesGetter.ClassNameInsertHandlerResult.CHECK_FOR_CORRECT_REFERENCE;
+  }
+}
index f1e4c57abf957e0b36f09c185d1b6069082b1db6..4eb8e5f27a30f0435d61a5ef57b94e7e8ebb6d1e 100644 (file)
@@ -784,7 +784,7 @@ public class JavaCompletionUtil {
 
   @Nullable
   public static PsiType getLookupElementType(final LookupElement element) {
-    final TypedLookupItem typed = element.as(TypedLookupItem.class);
+    TypedLookupItem typed = typedFrom(element);
     if (typed != null) {
       return typed.getType();
     }
@@ -805,6 +805,16 @@ public class JavaCompletionUtil {
     return qualifierType;
   }
 
+  public static @Nullable TypedLookupItem typedFrom(LookupElement element) {
+    TypedLookupItem typed = null;
+    if (element instanceof TypedLookupItem) typed = (TypedLookupItem)element;
+    else if (element instanceof LookupElementDecorator) {
+      element = ((LookupElementDecorator)element).getDelegate();
+      if (element instanceof TypedLookupItem) typed = (TypedLookupItem)element;
+    }
+    return typed;
+  }
+
   @Nullable
   public static PsiType getQualifiedMemberReferenceType(@Nullable PsiType qualifierType, @NotNull final PsiMember member) {
     final ClassCandidateInfo info = TypeConversionUtil.splitType(qualifierType, member);
index 67fa7e096bb3b283b9406214bdadf9a77ba5597b..1a58f978c4969c7c0683159a64a2cdbc64796a78 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.intellij.codeInsight.completion;
 
+import com.intellij.codeInsight.TailType;
 import com.intellij.codeInsight.completion.scope.CompletionElement;
 import com.intellij.codeInsight.completion.scope.JavaCompletionProcessor;
 import com.intellij.codeInsight.lookup.*;
@@ -135,11 +136,11 @@ public class JavaDocCompletionContributor extends CompletionContributor {
         ret.add(tokenizer.nextToken());
       }
       for (final String s : ret) {
-        final LookupItem item = (LookupItem)LookupItemUtil.objectToLookupItem(s);
         if (isInline) {
-          item.setInsertHandler(new InlineInsertHandler());
+          result.addElement(TailTypeDecorator.withInsertHandler(LookupElementBuilder.create(s), new InlineInsertHandler()));
+        } else {
+          result.addElement(TailTypeDecorator.withTail(LookupElementBuilder.create(s), TailType.SPACE));
         }
-        result.addElement(item);
       }
     }
 
@@ -149,8 +150,8 @@ public class JavaDocCompletionContributor extends CompletionContributor {
     }
   }
 
-  private static class InlineInsertHandler implements InsertHandler<LookupItem> {
-    public void handleInsert(InsertionContext context, LookupItem item) {
+  private static class InlineInsertHandler implements InsertHandler<LookupElement> {
+    public void handleInsert(InsertionContext context, LookupElement item) {
       if (context.getCompletionChar() == Lookup.REPLACE_SELECT_CHAR) {
         final Project project = context.getProject();
         PsiDocumentManager.getInstance(project).commitAllDocuments();
index 096d07f863bbcdfed2dc9078ca84dafcac9c5c64..9deefd5e3f7e693dce3dce8dc5db63625d931cb5 100644 (file)
@@ -219,7 +219,7 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
           final CompletionService service = CompletionService.getCompletionService();
           new BasicExpressionCompletionContributor().fillCompletionVariants(parameters, service.createResultSet(parameters, new Consumer<LookupElement>() {
             public void consume(final LookupElement lookupElement) {
-              final TypedLookupItem typed = lookupElement.as(TypedLookupItem.class);
+              final TypedLookupItem typed = JavaCompletionUtil.typedFrom(lookupElement);
               if (typed != null) {
                 final PsiType psiType = typed.getType();
                 if (psiType != null && type.isAssignableFrom(psiType)) {
index 1920fffbdf7e075f01e66d53d43ce1fe9d99c90d..654d58545fe47a11774b6f2544b3d4c3d824c34c 100644 (file)
@@ -25,11 +25,11 @@ import org.jetbrains.annotations.NotNull;
 public class PreferSimpleWeigher extends CompletionWeigher {
 
   public Comparable weigh(@NotNull final LookupElement item, final CompletionLocation location) {
-    final PsiTypeLookupItem lookupItem = item.as(PsiTypeLookupItem.class);
+    final PsiTypeLookupItem lookupItem = PsiTypeLookupItem.from(item);
     if (lookupItem != null) {
       return -lookupItem.getBracketsCount();
     }
-    if (item.as(CastingLookupElementDecorator.class) != null) {
+    if (CastingLookupElementDecorator.from(item) != null) {
       return -239;
     }
     return 0;
index 687ce14d5c2cfc666deeae6f388afba2cc1dc2e3..5ad8b86fddc17f5964782a6bb62dd9226e42b10e 100644 (file)
@@ -103,4 +103,14 @@ public class PsiTypeLookupItem extends LookupItem {
     }
     return new LookupItem(type, type.getPresentableText());
   }
+  
+  public static @Nullable PsiTypeLookupItem from(LookupElement element) {
+    if (element instanceof PsiTypeLookupItem) return (PsiTypeLookupItem)element;
+    else if (element instanceof LookupElementDecorator) {
+      element = ((LookupElementDecorator)element).getDelegate();
+      if (element instanceof PsiTypeLookupItem) return (PsiTypeLookupItem)element;
+    }
+    
+    return null;
+  }
 }
index 863b93555417b1f4189b40895c4945b002d5d0d0..0ad9eb7b9722516340ac104d7f26629351bdcc6e 100644 (file)
@@ -87,6 +87,7 @@ public abstract class AbstractQualifiedReference<T extends AbstractQualifiedRefe
   }
 
 
+  @NotNull
   public  String getCanonicalText() {
     return getText();
   }
index d81d710a97cece278e4ed9896ee71fe5e41586d6..65819311954b8cead6bc822b664fc2fbdb131a71 100644 (file)
@@ -166,7 +166,7 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
       }
     }
 
-    final ASTNode prevElement = FormattingAstUtil.getPrevElement(child);
+    final ASTNode prevElement = FormattingAstUtil.getPrevNonWhiteSpaceNode(child);
     if (prevElement != null && prevElement.getElementType() == JavaElementType.MODIFIER_LIST) {
       return Indent.getNoneIndent();
     }
@@ -561,6 +561,7 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo
     return role == ChildRole.OPERATION_SIGN || role == ChildRole.COLON;
   }
 
+  @SuppressWarnings({"ConstantConditions"})
   private Block createMethodCallExpressionBlock(final ASTNode node, final Wrap blockWrap, final Alignment alignment) {
     final ArrayList<ASTNode> nodes = new ArrayList<ASTNode>();
     final ArrayList<Block> subBlocks = new ArrayList<Block>();
index 6baba318732e450f04fb710d42c703692fa1a3ed..06b6c1603d0162dab4b31f8e23fb935c1e42e581 100644 (file)
@@ -99,10 +99,10 @@ public class BlockContainingJavaBlock extends AbstractJavaBlock{
 
   private Indent calcIndent(final ASTNode child, final int state) {
     if (state == AFTER_ELSE && child.getElementType() == ElementType.IF_STATEMENT) {
-      if (!mySettings.SPECIAL_ELSE_IF_TREATMENT) {
-        return getCodeBlockInternalIndent(1);
+      if (mySettings.SPECIAL_ELSE_IF_TREATMENT) {
+        return Indent.getNoneIndent();
       } else {
-        return getCodeBlockExternalIndent();
+        return getCodeBlockInternalIndent(1);
       }
     }
     if (isSimpleStatement(child)){
index f23eb0f72a605a37324418531ade5e7e68c955b1..fbd907e136afdd0b13d6a97149339206da2d3f96 100644 (file)
@@ -51,14 +51,29 @@ public class FormattingAstUtil {
    * @return        left non-white space sibling of the given node if any; <code>null</code> otherwise
    */
   @Nullable
-  public static ASTNode getPrevElement(final ASTNode node) {
+  public static ASTNode getPrevNonWhiteSpaceNode(final ASTNode node) {
     ASTNode result = node.getTreePrev();
-    while (result != null && result.getElementType() == TokenType.WHITE_SPACE) {
+    while (result != null && (result.getElementType() == TokenType.WHITE_SPACE || result.getTextLength() == 0)) {
       result = result.getTreePrev();
     }
     return result;
   }
 
+  /**
+   * Tries to get next non-white space <code>AST</code> node for the given one.
+   *
+   * @param node    base node which right non-white space sibling is to be found
+   * @return        right non-white space sibling of the given node if any; <code>null</code> otherwise
+   */
+  @Nullable
+  public static ASTNode getNextNonWhiteSpaceNode(final ASTNode node) {
+    ASTNode result = node.getTreeNext();
+    while (result != null && (result.getElementType() == TokenType.WHITE_SPACE || result.getTextLength() == 0)) {
+      result = result.getTreeNext();
+    }
+    return result;
+  }
+
   /**
    * Allows to answer if given node wraps assignement operation.
    *
index 61fdd9f7f7c3939a7eb0710ca0d02836c442dee8..fb0f1b253dc20678ae5204ff0707f8c76069a926 100644 (file)
@@ -27,6 +27,7 @@ import com.intellij.pom.java.LanguageLevel;
 import com.intellij.psi.*;
 import com.intellij.psi.codeStyle.CodeStyleSettings;
 import com.intellij.psi.formatter.FormatterUtil;
+import com.intellij.psi.formatter.java.spacing.JavaBraceSpacingProcessor;
 import com.intellij.psi.impl.source.SourceTreeToPsiMap;
 import com.intellij.psi.impl.source.codeStyle.ImportHelper;
 import com.intellij.psi.impl.source.javadoc.PsiDocMethodOrFieldRef;
@@ -45,7 +46,9 @@ import com.intellij.util.containers.ConcurrentHashMap;
 import java.util.Map;
 
 public class JavaSpacePropertyProcessor extends JavaElementVisitor {
-  private static final Logger LOG = Logger.getInstance("#com.intellij.psi.formatter.java.JavaSpacePropertyProcessor"); 
+  private static final Logger LOG = Logger.getInstance("#com.intellij.psi.formatter.java.JavaSpacePropertyProcessor");
+
+  private final JavaBraceSpacingProcessor myBraceSpacingProcessor;
 
   private PsiElement myParent;
   private int myRole1;
@@ -63,7 +66,13 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor {
 
   private static final ThreadLocal<JavaSpacePropertyProcessor> mySharedProcessorAllocator = new ThreadLocal<JavaSpacePropertyProcessor>();
 
-  private JavaSpacePropertyProcessor() {}
+  private JavaSpacePropertyProcessor() {
+    this(JavaBraceSpacingProcessor.INSTANCE);
+  }
+
+  public JavaSpacePropertyProcessor(JavaBraceSpacingProcessor braceSpacingProcessor) {
+    myBraceSpacingProcessor = braceSpacingProcessor;
+  }
 
   private void doInit(final ASTNode child, final CodeStyleSettings settings) {
     init(child);
@@ -204,8 +213,7 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor {
     }
     else if (myRole1 == ChildRole.LBRACE) {
       if (!(aClass instanceof PsiAnonymousClass)) {
-        myResult = Spacing.createSpacing(0, 0, mySettings.BLANK_LINES_AFTER_CLASS_HEADER + 1,
-                                         mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_DECLARATIONS);
+        myResult = myBraceSpacingProcessor.getLBraceSpacing(mySettings, myChild2);
       } else {
         if (myRole2 == ChildRole.CLASS_INITIALIZER && isTheOnlyClassMember(myChild2)) {
           myResult = Spacing.createSpacing(0, 0, 0,
@@ -273,8 +281,7 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor {
     }
     else if (myRole1 == ChildRole.CLASS_INITIALIZER) {
       if (myRole2 == ChildRole.RBRACE) {
-        myResult = Spacing
-          .createSpacing(0, Integer.MAX_VALUE, isInsideAnonimusClass() ? 0 : 1, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_BEFORE_RBRACE);
+        myResult = myBraceSpacingProcessor.getRBraceSpacing(mySettings, myChild1, isInsideAnonimusClass());
       }
       else {
         final int blankLines = getLinesAroundMethod() + 1;
@@ -525,19 +532,20 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor {
   }
 
   @Override public void visitTryStatement(PsiTryStatement statement) {
-    if (myRole2 == ChildRole.FINALLY_KEYWORD) {
-      processOnNewLineCondition(mySettings.FINALLY_ON_NEW_LINE);
-    }
-    else if (myRole2 == ChildRole.TRY_BLOCK) {
-      myResult = getSpaceBeforeLBrace(mySettings.SPACE_BEFORE_TRY_LBRACE, mySettings.BRACE_STYLE, null,
-                                      mySettings.KEEP_SIMPLE_BLOCKS_IN_ONE_LINE);
+    if (myRole2 == ChildRole.FINALLY_KEYWORD || myRole2 == ChildRole.CATCH_SECTION) {
+      boolean putRightChildOnNewLine = myRole2 == ChildRole.FINALLY_KEYWORD ? mySettings.FINALLY_ON_NEW_LINE : mySettings.CATCH_ON_NEW_LINE;
+      if (putRightChildOnNewLine) {
+        processOnNewLineCondition(mySettings.FINALLY_ON_NEW_LINE);
+      } else {
+        createSpaceProperty(true, false, 0);
+      }
+      return;
     }
-    else if (myRole2 == ChildRole.FINALLY_BLOCK) {
-      myResult = getSpaceBeforeLBrace(mySettings.SPACE_BEFORE_FINALLY_LBRACE, mySettings.BRACE_STYLE, null,
-                                      mySettings.KEEP_SIMPLE_BLOCKS_IN_ONE_LINE);
-    }    
-    else if (myRole2 == ChildRole.CATCH_SECTION) {
-      processOnNewLineCondition(mySettings.CATCH_ON_NEW_LINE);
+
+    if (myRole2 == ChildRole.TRY_BLOCK || myRole2 == ChildRole.FINALLY_BLOCK) {
+      boolean useSpaceBeforeLBrace = myRole2 == ChildRole.TRY_BLOCK ? mySettings.SPACE_BEFORE_TRY_LBRACE
+                                                                    : mySettings.SPACE_BEFORE_FINALLY_LBRACE;
+      myResult = getSpaceBeforeLBrace(useSpaceBeforeLBrace, mySettings.BRACE_STYLE, null, mySettings.KEEP_SIMPLE_BLOCKS_IN_ONE_LINE);
     }
   }
 
diff --git a/java/java-impl/src/com/intellij/psi/formatter/java/spacing/JavaBraceSpacingProcessor.java b/java/java-impl/src/com/intellij/psi/formatter/java/spacing/JavaBraceSpacingProcessor.java
new file mode 100644 (file)
index 0000000..8548c25
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2000-2010 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.psi.formatter.java.spacing;
+
+import com.intellij.formatting.Spacing;
+import com.intellij.lang.ASTNode;
+import com.intellij.psi.JavaTokenType;
+import com.intellij.psi.codeStyle.CodeStyleSettings;
+import com.intellij.psi.formatter.java.FormattingAstUtil;
+
+/**
+ * Utility class that encapsulates algorithm of defining {@link Spacing} to use for the target code block containing brace.
+ * <p/>
+ * This class is not singleton but it's thread-safe and provides single-point-of-usage field {@link #INSTANCE}.
+ * <p/>
+ * Thread-safe.
+ *
+ * @author Denis Zhdanov
+ * @since Apr 26, 2010 1:52:52 PM
+ */
+public class JavaBraceSpacingProcessor {
+
+  /** Single-point-of-usage field. */
+  public static final JavaBraceSpacingProcessor INSTANCE = new JavaBraceSpacingProcessor();
+
+  /**
+   * Allows to get {@link Spacing} to use for the given AST node that is assumed to be right sibling of left curly brace and that brace.
+   *
+   * @param settings      code formatting settings to use
+   * @param rightNode     right sibling of target left curly brace
+   * @return              spacing to use for the left curly brace and it's given right sibling
+   */
+  @SuppressWarnings({"MethodMayBeStatic"})
+  public Spacing getLBraceSpacing(CodeStyleSettings settings, ASTNode rightNode) {
+    if (shouldUseFlyingGeeseStyleForLeftBrace(settings, rightNode)) {
+      return getFlyingGeesSpacing(settings);
+    }
+    return Spacing.createSpacing(
+      0, 0, settings.BLANK_LINES_AFTER_CLASS_HEADER + 1, settings.KEEP_LINE_BREAKS, settings.KEEP_BLANK_LINES_IN_DECLARATIONS
+    );
+  }
+
+  /**
+   * Allows to get {@link Spacing} to use for the given AST node that is assumed to be left sibling of right curly brace and that brace.
+   *
+   * @param settings      code formatting settings to use
+   * @param leftNode      left sibling of target right curly brace
+   * @return              spacing to use for the right curly brace and it's given left sibling
+   */
+  @SuppressWarnings({"MethodMayBeStatic"})
+  public Spacing getRBraceSpacing(CodeStyleSettings settings, ASTNode leftNode, boolean insideAnonymousClass) {
+    if (shouldUseFlyingGeeseStyleForRightBrace(settings, leftNode)) {
+      return getFlyingGeesSpacing(settings);
+    }
+    return Spacing.createSpacing(
+      0, Integer.MAX_VALUE, insideAnonymousClass ? 0 : 1, settings.KEEP_LINE_BREAKS, settings.KEEP_BLANK_LINES_BEFORE_RBRACE
+    );
+  }
+
+  private static boolean shouldUseFlyingGeeseStyleForLeftBrace(CodeStyleSettings settings, ASTNode rightNode) {
+    if (!settings.USE_FLYING_GEESE_BRACES) {
+      return false;
+    }
+
+    ASTNode rightSibling = FormattingAstUtil.getNextNonWhiteSpaceNode(rightNode);
+    return rightSibling != null && rightSibling.getElementType() == JavaTokenType.RBRACE;
+  }
+
+  private static boolean shouldUseFlyingGeeseStyleForRightBrace(CodeStyleSettings settings, ASTNode leftNode) {
+    if (!settings.USE_FLYING_GEESE_BRACES) {
+      return false;
+    }
+
+    ASTNode leftSibling = FormattingAstUtil.getPrevNonWhiteSpaceNode(leftNode);
+    return leftSibling != null && leftSibling.getElementType() == JavaTokenType.LBRACE;
+  }
+
+  private static Spacing getFlyingGeesSpacing(CodeStyleSettings settings) {
+    return Spacing.createSpacing(settings.FLYING_GEESE_BRACES_GAP, settings.FLYING_GEESE_BRACES_GAP, 0, false, 0);
+  }
+}
index e4f1c2fb53cf506ea232189bbf80664ec2896fb4..c7f7ae1278b532b85720eb07cc5e0af78e40220b 100644 (file)
@@ -153,7 +153,7 @@ public class JavaChildWrapArranger {
       if (childType == JavaElementType.ANNOTATION) {
         return reservedWrapsProvider.getReservedWrap(JavaElementType.MODIFIER_LIST);
       }
-      ASTNode prevElement = FormattingAstUtil.getPrevElement(child);
+      ASTNode prevElement = FormattingAstUtil.getPrevNonWhiteSpaceNode(child);
       if (prevElement != null && prevElement.getElementType() == JavaElementType.ANNOTATION) {
         return reservedWrapsProvider.getReservedWrap(JavaElementType.MODIFIER_LIST);
       }
index 4381d526f87b371e0300d16362dae8df05d08819..096f1efe87098466c124e23fd2fae4eaca7e6324 100644 (file)
@@ -324,7 +324,7 @@ public class PsiClassImplUtil {
   };
 
   public static Icon getClassIcon(final int flags, final PsiClass aClass) {
-    Icon base = aClass.getUserData(Iconable.LAST_COMPUTED_ICON);
+    Icon base = Iconable.LastComputedIcon.get(aClass, flags);
     if (base == null) {
       Icon symbolIcon = ElementPresentationUtil.getClassIconOfKind(aClass, ElementPresentationUtil.getBasicClassKind(aClass));
       RowIcon baseIcon = ElementBase.createLayeredIcon(symbolIcon, 0);
index 403654b77975e3e9aa2ac256823884d8e15d9dec..432e5877843b53e55663f4db5861fae90e3fa36d 100644 (file)
@@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Comparing;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.psi.*;
+import com.intellij.psi.augment.PsiAugmentProvider;
 import com.intellij.psi.filters.ElementFilter;
 import com.intellij.psi.impl.light.LightClassReference;
 import com.intellij.psi.impl.source.PsiClassReferenceType;
@@ -59,10 +60,17 @@ public class PsiImplUtil {
   @NotNull
   public static PsiMethod[] getConstructors(@NotNull PsiClass aClass) {
     final List<PsiMethod> constructorsList = new SmartList<PsiMethod>();
+
     final PsiMethod[] methods = aClass.getMethods();
     for (final PsiMethod method : methods) {
       if (method.isConstructor()) constructorsList.add(method);
     }
+
+    final List<PsiMethod> augments = PsiAugmentProvider.collectAugments(aClass, PsiMethod.class);
+    for (final PsiMethod method : augments) {
+      if (method.isConstructor()) constructorsList.add(method);
+    }
+
     return constructorsList.toArray(new PsiMethod[constructorsList.size()]);
   }
 
index 57adfbf230427ad9c6150440dec90c4b6060c28b..f99f24f8d252aafd2d6d6dd1c5c04c54f7af2c36 100644 (file)
@@ -95,6 +95,7 @@ public class ClsJavaCodeReferenceElementImpl extends ClsElementImpl implements P
     return this;
   }
 
+  @NotNull
   public String getCanonicalText() {
     return myCanonicalText;
   }
index 2983154903b66e2ddf6fb0c4fa9cd15c8754c997..4fc4696f75a800dd0edade7207750288f3926f26 100644 (file)
@@ -121,6 +121,7 @@ public class ClsReferenceExpressionImpl extends ClsElementImpl implements PsiRef
     return new TextRange(0, getTextLength());
   }
 
+  @NotNull
   public String getCanonicalText() {
     return myPatternExpression.getCanonicalText();
   }
index 2c9c154b800c2f0c7fb52a6f12e0dc2314dc55c4..4133b98a8123c16119bf3f4fee9627d2ad77c742 100644 (file)
@@ -107,6 +107,7 @@ public class ClsTypeParameterReferenceImpl extends ClsElementImpl implements Psi
     return false;
   }
 
+  @NotNull
   public String getCanonicalText() {
     return myName;
   }
index 6e9331b4a524fdccb194154d3704881e51256405..c46f0aef4e87c0848727f6952a00b58f24a20f11 100644 (file)
@@ -168,6 +168,7 @@ public class LightClassReference extends LightElement implements PsiJavaCodeRefe
     return this;
   }
 
+  @NotNull
   public String getCanonicalText() {
     String name = getQualifiedName();
     if (name == null) return null;
index b02a2c66fb82d5b8e82383bd89921c928bf09fec..7032bd44cc4b8863f151255994205058a7c9ba1b 100644 (file)
@@ -95,6 +95,7 @@ public class LightMemberReference extends LightElement implements PsiJavaCodeRef
     return this;
   }
 
+  @NotNull
   public String getCanonicalText() {
     String name = getQualifiedName();
     if (name == null) return null;
index c6b7e8c8a42de1f7a03f8f9dc813491f2a710136..49a055c9c9fea3937512f70bca1667ed54ff7d72 100644 (file)
@@ -73,6 +73,7 @@ public class LightPackageReference extends LightElement implements PsiJavaCodeRe
     return this;
   }
 
+  @NotNull
   public String getCanonicalText(){
     return getText();
   }
index 75796c8dd24f9f3a596d2081e8eeefa4c5639283..437a678cbb1ea55a0dc319967ed8755999bcda55 100644 (file)
@@ -228,6 +228,7 @@ public class PsiEnumConstantImpl extends JavaStubPsiElement<PsiFieldStub> implem
       return advancedResolve(false).getElement();
     }
 
+    @NotNull
     public String getCanonicalText() {
       return getContainingClass().getName();
     }
index 1528fd1b25dc74b344d97756c58396bfd811f037..541d80207ca1dfdefcc505191a46f05f379221be 100644 (file)
@@ -182,6 +182,7 @@ public class PsiImportStaticReferenceElementImpl extends CompositePsiElement imp
     return new TextRange(startOffset, startOffset + nameChild.getTextLength());
   }
 
+  @NotNull
   public String getCanonicalText() {
     String canonicalText = myCanonicalText;
     if (canonicalText == null) {
index cb280f2e422a67dfdefc067b292f0fcea4d00806..4c32e03f3e62495b3c43bb9a9cbcf6537cf2526c 100644 (file)
@@ -263,6 +263,7 @@ public class PsiJavaCodeReferenceElementImpl extends CompositePsiElement impleme
     }
   }
 
+  @NotNull
   public String getCanonicalText() {
     switch (getKind()) {
       case CLASS_NAME_KIND:
index fe1dac35655ce1225412e18a17fc2023bbf96b0c..9572fa180e51c485099e49d9ce25ba2d25722507 100644 (file)
@@ -65,6 +65,7 @@ public class PsiLabelReference implements PsiReference{
       return null;
     }
 
+    @NotNull
     public String getCanonicalText(){
       return getElement().getText();
     }
index 4ba92eed93e4c2b9ac923dd7b7363a1ee077937c..b6902af7d931ff044890115352b85774bc8ad73d 100644 (file)
@@ -267,6 +267,7 @@ public class PsiDocMethodOrFieldRef extends CompositePsiElement implements PsiDo
       return false;
     }
 
+    @NotNull
     public String getCanonicalText() {
       return getNameElement().getText();
     }
index 992e92302a3ad41b2f8f63560045ece4bdc9105c..d1ed0fbe0b06c639b6cd76ad5eae7005d0fee0ed 100644 (file)
@@ -23,10 +23,11 @@ import com.intellij.psi.impl.source.tree.CompositePsiElement;
 import com.intellij.psi.impl.source.tree.Factory;
 import com.intellij.psi.impl.source.tree.LeafElement;
 import com.intellij.psi.impl.source.tree.SharedImplUtil;
+import com.intellij.psi.infos.CandidateInfo;
 import com.intellij.psi.javadoc.PsiDocTagValue;
 import com.intellij.psi.javadoc.PsiDocToken;
+import com.intellij.psi.scope.PsiScopeProcessor;
 import com.intellij.psi.util.PsiTreeUtil;
-import com.intellij.util.ArrayUtil;
 import com.intellij.util.CharTable;
 import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.NotNull;
@@ -54,26 +55,33 @@ public class PsiDocParamRef extends CompositePsiElement implements PsiDocTagValu
         !(owner instanceof PsiClass)) return null;
     final ASTNode valueToken = findChildByType(JavaDocTokenType.DOC_TAG_VALUE_TOKEN);
     if (valueToken == null) return null;
-    myCachedReference = cachedReference = new PsiReference() {
-      public PsiElement resolve() {
-        String name = valueToken.getText();
-        final PsiElement firstChild = getFirstChild();
-        if (firstChild instanceof PsiDocToken && ((PsiDocToken)firstChild).getTokenType().equals(JavaDocTokenType.DOC_TAG_VALUE_LT)) {
-          final PsiTypeParameter[] typeParameters = ((PsiTypeParameterListOwner)owner).getTypeParameters();
-          for (PsiTypeParameter typeParameter : typeParameters) {
-            if (typeParameter.getName().equals(name)) return typeParameter;
-          }
+    final String name = valueToken.getText();
+    PsiElement reference = null;
+    final PsiElement firstChild = getFirstChild();
+    if (firstChild instanceof PsiDocToken && ((PsiDocToken)firstChild).getTokenType().equals(JavaDocTokenType.DOC_TAG_VALUE_LT)) {
+      final PsiTypeParameter[] typeParameters = ((PsiTypeParameterListOwner)owner).getTypeParameters();
+      for (PsiTypeParameter typeParameter : typeParameters) {
+        if (typeParameter.getName().equals(name)) {
+          reference = typeParameter;
         }
-        else if (owner instanceof PsiMethod) {
-          final PsiParameter[] parameters = ((PsiMethod)owner).getParameterList().getParameters();
-          for (PsiParameter parameter : parameters) {
-            if (parameter.getName().equals(name)) return parameter;
-          }
+      }
+    }
+    else if (owner instanceof PsiMethod) {
+      final PsiParameter[] parameters = ((PsiMethod)owner).getParameterList().getParameters();
+      for (PsiParameter parameter : parameters) {
+        if (parameter.getName().equals(name)) {
+          reference = parameter;
         }
+      }
+    }
 
-        return null;
+    final PsiElement resultReference = reference;
+    myCachedReference = cachedReference = new PsiJavaReference() {
+      public PsiElement resolve() {
+        return resultReference;
       }
 
+      @NotNull
       public String getCanonicalText() {
         return valueToken.getText();
       }
@@ -101,14 +109,14 @@ public class PsiDocParamRef extends CompositePsiElement implements PsiDocTagValu
       }
 
       @NotNull
-      public Object[] getVariants() {
+      public PsiElement[] getVariants() {
         final PsiElement firstChild = getFirstChild();
         if (firstChild instanceof PsiDocToken && ((PsiDocToken)firstChild).getTokenType().equals(JavaDocTokenType.DOC_TAG_VALUE_LT)) {
           return ((PsiTypeParameterListOwner)owner).getTypeParameters();
         } else if (owner instanceof PsiMethod) {
           return ((PsiMethod)owner).getParameterList().getParameters();
         }
-        return ArrayUtil.EMPTY_OBJECT_ARRAY;
+        return PsiElement.EMPTY_ARRAY;
       }
 
       public boolean isSoft(){
@@ -123,6 +131,26 @@ public class PsiDocParamRef extends CompositePsiElement implements PsiDocTagValu
       public PsiElement getElement() {
         return PsiDocParamRef.this;
       }
+
+      public void processVariants(PsiScopeProcessor processor) {
+        for (final PsiElement element : getVariants()) {
+          if (!processor.execute(element, ResolveState.initial())) {
+            return;
+          }
+        }
+      }
+
+      @NotNull
+      public JavaResolveResult advancedResolve(boolean incompleteCode) {
+        return resultReference == null ? JavaResolveResult.EMPTY : new CandidateInfo(resultReference, PsiSubstitutor.EMPTY);
+      }
+
+      @NotNull
+      public JavaResolveResult[] multiResolve(boolean incompleteCode) {
+        return resultReference == null
+               ? JavaResolveResult.EMPTY_ARRAY
+               : new JavaResolveResult[]{new CandidateInfo(resultReference, PsiSubstitutor.EMPTY)};
+      }
     };
     return cachedReference;
   }
index 49860ba3b2c9288834a750c03a06dfbbf0c58c3e..8e8890f27c511ed869f803c05991436ed81d8b79 100644 (file)
@@ -159,6 +159,7 @@ public class JavaClassReference extends GenericReference implements PsiJavaRefer
     return myRange;
   }
 
+  @NotNull
   public String getCanonicalText() {
     return myText;
   }
index 9b0cf8fd6df951cb7201edad8ed69ea0b7eda0b7..3597fea5840c31173fc6604de0accea57af280d4 100644 (file)
@@ -158,6 +158,7 @@ public class PsiNameValuePairImpl extends CompositePsiElement implements PsiName
         return MethodSignatureUtil.findMethodBySignature(refClass, signature, false);
       }
 
+      @NotNull
       public String getCanonicalText() {
         String name = getName();
         return name != null ? name : PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME;
index 08b7ec622f15e5cdc79586e225ef70bd2be61831..798fac111c3d72b6932685ae5daa8af4905fc67a 100644 (file)
@@ -148,6 +148,7 @@ public class PsiNewExpressionImpl extends ExpressionPsiElement implements PsiNew
         return null;
       }
 
+      @NotNull
       public String getCanonicalText() {
         return null;
       }
index deea549bc0d10f2475c4e9b18d64d55b37d8cc15..16c1b2ca634cf937994361a5cdb9b0de9269286d 100644 (file)
@@ -291,6 +291,7 @@ public class PsiReferenceExpressionImpl extends ExpressionPsiElement implements
     return (JavaResolveResult[])results;
   }
 
+  @NotNull
   public String getCanonicalText() {
     PsiElement element = resolve();
     if (element instanceof PsiClass) return ((PsiClass)element).getQualifiedName();
index ac39286e706319d91b15ad41a76deca09115df20..38d818e35e973e683d228447b840a2d2f8d74322 100644 (file)
@@ -18,8 +18,8 @@ package com.intellij.psi.util.proximity;
 import com.intellij.psi.*;
 import com.intellij.psi.util.ProximityLocation;
 import com.intellij.psi.util.PsiTreeUtil;
-import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 /**
index e351932529dc486be13ceb6f1c42d28c9231151b..2b624ad14c110ffe0bdf520d86841e201adb36a7 100644 (file)
@@ -31,6 +31,7 @@ import com.intellij.psi.codeStyle.CodeStyleManager;
 import com.intellij.psi.util.*;
 import com.intellij.refactoring.BaseRefactoringProcessor;
 import com.intellij.refactoring.RefactoringBundle;
+import com.intellij.refactoring.rename.RenameUtil;
 import com.intellij.refactoring.ui.ConflictsDialog;
 import com.intellij.refactoring.util.CanonicalTypes;
 import com.intellij.usageView.UsageInfo;
@@ -137,9 +138,15 @@ public class ChangeSignatureProcessor extends BaseRefactoringProcessor {
       }
     }
 
-    final Set<UsageInfo> usagesSet = new HashSet<UsageInfo>(Arrays.asList(refUsages.get()));
+    final UsageInfo[] usagesIn = refUsages.get();
+    Set<UsageInfo> usagesSet = new HashSet<UsageInfo>(Arrays.asList(usagesIn));
+    RenameUtil.removeConflictUsages(usagesSet);
     if (myPrepareSuccessfulSwingThreadCallback != null && !conflictDescriptions.isEmpty()) {
-      ConflictsDialog dialog = new ConflictsDialog(myProject, conflictDescriptions);
+      ConflictsDialog dialog = new ConflictsDialog(myProject, conflictDescriptions, new Runnable(){
+        public void run() {
+          execute(usagesIn);
+        }
+      });
       dialog.show();
       if (!dialog.isOK()) {
         if (dialog.isShowConflicts()) prepareSuccessful();
index aed16d3c631a00a713f6ba60d45d198b8e46646a..d0e9c6c0db7e3fcd172a981516aca9d65e4d8488 100644 (file)
@@ -172,7 +172,7 @@ public class ConvertToInstanceMethodProcessor extends BaseRefactoringProcessor {
       LOG.error(e);
     }
 
-    return showConflicts(conflicts);
+    return showConflicts(conflicts, usagesIn);
   }
 
   private void addInaccessibilityConflicts(final UsageInfo[] usages, final MultiMap<PsiElement, String> conflicts) throws IncorrectOperationException {
index 13bf9964620e2f90b70f86775ce0eb7048139daa..24edd4ec313bdfb3f75f45b3899be1c581007384 100644 (file)
@@ -127,7 +127,7 @@ public class EncapsulateFieldsProcessor extends BaseRefactoringProcessor {
         }
       }
     }
-    return showConflicts(conflicts);
+    return showConflicts(conflicts, refUsages.get());
   }
 
   private void checkExistingMethods(PsiMethod[] prototypes, MultiMap<PsiElement, String> conflicts, boolean isGetter) {
index e3eca3742431f45439e9409fdd00c73f05e43ff8..51244b582106b710f68e3efc7cb32e210e36d251 100644 (file)
@@ -131,30 +131,25 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor {
 
     if (!myGenerateAccessors) {
       calculateInitializersConflicts(conflicts);
-      final NecessaryAccessorsVisitor visitor = new NecessaryAccessorsVisitor();
-      for (PsiField field : fields) {
-        field.accept(visitor);
-      }
-      for (PsiMethod method : methods) {
-        method.accept(visitor);
-      }
-      for (PsiClass innerClass : innerClasses) {
-        innerClass.accept(visitor);
-      }
-
-      final Set<PsiField> fieldsNeedingGetter = visitor.getFieldsNeedingGetter();
+      final NecessaryAccessorsVisitor visitor = checkNecessaryGettersSetters4ExtractedClass();
+      final NecessaryAccessorsVisitor srcVisitor = checkNecessaryGettersSetters4SourceClass();
+      final Set<PsiField> fieldsNeedingGetter = new LinkedHashSet<PsiField>();
+      fieldsNeedingGetter.addAll(visitor.getFieldsNeedingGetter());
+      fieldsNeedingGetter.addAll(srcVisitor.getFieldsNeedingGetter());
       for (PsiField field : fieldsNeedingGetter) {
         conflicts.putValue(field, "Field \'" + field.getName() + "\' needs getter");
       }
-      final Set<PsiField> fieldsNeedingSetter = visitor.getFieldsNeedingSetter();
+      final Set<PsiField> fieldsNeedingSetter = new LinkedHashSet<PsiField>();
+      fieldsNeedingSetter.addAll(visitor.getFieldsNeedingSetter());
+      fieldsNeedingSetter.addAll(srcVisitor.getFieldsNeedingSetter());
       for (PsiField field : fieldsNeedingSetter) {
-        conflicts.putValue(field, "Field \'" + field.getName() + "\' needs getter");
+        conflicts.putValue(field, "Field \'" + field.getName() + "\' needs setter");
       }
     }
-    return showConflicts(conflicts);
+    return showConflicts(conflicts, refUsages.get());
   }
 
-  
+
   private void calculateInitializersConflicts(MultiMap<PsiElement, String> conflicts) {
     final PsiClassInitializer[] initializers = sourceClass.getInitializers();
     for (PsiClassInitializer initializer : initializers) {
@@ -271,16 +266,7 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor {
     }
 
     if (myGenerateAccessors) {
-      final NecessaryAccessorsVisitor visitor = new NecessaryAccessorsVisitor();
-      for (PsiField field : fields) {
-        field.accept(visitor);
-      }
-      for (PsiMethod method : methods) {
-        method.accept(visitor);
-      }
-      for (PsiClass innerClass : innerClasses) {
-        innerClass.accept(visitor);
-      }
+      final NecessaryAccessorsVisitor visitor = checkNecessaryGettersSetters4SourceClass();
       for (PsiField field : visitor.getFieldsNeedingGetter()) {
         sourceClass.add(PropertyUtil.generateGetterPrototype(field));
       }
@@ -296,6 +282,83 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor {
     }
   }
 
+  private NecessaryAccessorsVisitor checkNecessaryGettersSetters4SourceClass() {
+    final NecessaryAccessorsVisitor visitor = new NecessaryAccessorsVisitor() {
+      @Override
+      protected boolean hasGetterOrSetter(PsiMethod[] getters) {
+        for (PsiMethod getter : getters) {
+          if (!isInMovedElement(getter)) return true;
+        }
+        return false;
+      }
+
+      @Override
+      protected boolean isProhibitedReference(PsiField field) {
+        if (fields.contains(field)) {
+          return false;
+        }
+        if (innerClasses.contains(field.getContainingClass())) {
+          return false;
+        }
+        return true;
+      }
+    };
+    for (PsiField field : fields) {
+      field.accept(visitor);
+    }
+    for (PsiMethod method : methods) {
+      method.accept(visitor);
+    }
+    for (PsiClass innerClass : innerClasses) {
+      innerClass.accept(visitor);
+    }
+    return visitor;
+  }
+
+  private NecessaryAccessorsVisitor checkNecessaryGettersSetters4ExtractedClass() {
+    final NecessaryAccessorsVisitor visitor = new NecessaryAccessorsVisitor() {
+      @Override
+      protected boolean hasGetterOrSetter(PsiMethod[] getters) {
+        for (PsiMethod getter : getters) {
+          if (isInMovedElement(getter)) return true;
+        }
+        return false;
+      }
+
+      @Override
+      protected boolean isProhibitedReference(PsiField field) {
+        if (fields.contains(field)) {
+          return true;
+        }
+        if (innerClasses.contains(field.getContainingClass())) {
+          return true;
+        }
+        return false;
+      }
+
+      @Override
+      public void visitMethod(PsiMethod method) {
+        if (methods.contains(method)) return;
+        super.visitMethod(method);
+      }
+
+      @Override
+      public void visitField(PsiField field) {
+        if (fields.contains(field)) return;
+        super.visitField(field);
+      }
+
+      @Override
+      public void visitClass(PsiClass aClass) {
+        if (innerClasses.contains(aClass)) return;
+        super.visitClass(aClass);
+      }
+
+    };
+    sourceClass.accept(visitor);
+    return visitor;
+  }
+
 
   private void buildDelegate() {
     final PsiManager manager = sourceClass.getManager();
@@ -501,8 +564,25 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor {
     final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
 
     final String qualifiedName = StringUtil.getQualifiedName(newPackageName, newClassName);
-    @NonNls final String getter = PropertyUtil.suggestGetterName(myProject, field);
-    @NonNls final String setter = PropertyUtil.suggestSetterName(myProject, field);
+    @NonNls String getter = null;
+    if (myGenerateAccessors) {
+      getter = PropertyUtil.suggestGetterName(myProject, field);
+    } else {
+      final PsiMethod fieldGetter = PropertyUtil.findPropertyGetter(sourceClass, field.getName(), false, false);
+      if (fieldGetter != null && isInMovedElement(fieldGetter)) {
+        getter = fieldGetter.getName();
+      }
+    }
+
+    @NonNls String setter = null;
+    if (myGenerateAccessors) {
+      setter = PropertyUtil.suggestSetterName(myProject, field);
+    } else {
+      final PsiMethod fieldSetter = PropertyUtil.findPropertySetter(sourceClass, field.getName(), false, false);
+      if (fieldSetter != null && isInMovedElement(fieldSetter)) {
+        setter = fieldSetter.getName();
+      }
+    }
     final boolean isStatic = field.hasModifierProperty(PsiModifier.STATIC);
 
     for (PsiReference reference : ReferencesSearch.search(field, scope)) {
@@ -516,19 +596,19 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor {
         if (RefactoringUtil.isPlusPlusOrMinusMinus(exp.getParent())) {
           usages.add(isStatic
                      ? new ReplaceStaticVariableIncrementDecrement(exp, qualifiedName)
-                     : new ReplaceInstanceVariableIncrementDecrement(exp, delegateFieldName, setter, getter));
+                     : new ReplaceInstanceVariableIncrementDecrement(exp, delegateFieldName, setter, getter, field.getName()));
         }
         else if (RefactoringUtil.isAssignmentLHS(exp)) {
           usages.add(isStatic
                      ? new ReplaceStaticVariableAssignment(exp, qualifiedName)
                      : new ReplaceInstanceVariableAssignment(PsiTreeUtil.getParentOfType(exp, PsiAssignmentExpression.class),
-                                                             delegateFieldName, setter, getter));
+                                                             delegateFieldName, setter, getter, field.getName()));
 
         }
         else {
           usages.add(isStatic
                      ? new ReplaceStaticVariableAccess(exp, qualifiedName)
-                     : new ReplaceInstanceVariableAccess(exp, delegateFieldName, getter));
+                     : new ReplaceInstanceVariableAccess(exp, delegateFieldName, getter, field.getName()));
         }
 
         if (!isStatic) {
@@ -540,21 +620,6 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor {
     }
   }
 
-  private boolean hasGetter(final PsiField field) {
-    return hasGetterOrSetter(sourceClass.findMethodsBySignature(PropertyUtil.generateGetterPrototype(field), false));
-  }
-
-  private boolean hasSetter(final PsiField field) {
-    return hasGetterOrSetter(sourceClass.findMethodsBySignature(PropertyUtil.generateSetterPrototype(field), false));
-  }
-
-  private boolean hasGetterOrSetter(final PsiMethod[] getters) {
-    for (PsiMethod getter : getters) {
-      if (!isInMovedElement(getter)) return true;
-    }
-    return false;
-  }
-
 
   private PsiClass buildClass() {
     final PsiManager manager = sourceClass.getManager();
@@ -579,18 +644,7 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor {
     extractedClassBuilder.setInterfaces(interfaces);
 
     if (myGenerateAccessors) {
-      final NecessaryAccessorsVisitor visitor = new NecessaryAccessorsVisitor() {
-        @Override
-        protected boolean isProhibitedReference(PsiField field) {
-          if (fields.contains(field)) {
-            return true;
-          }
-          if (innerClasses.contains(field.getContainingClass())) {
-            return true;
-          }
-          return false;
-        }
-      };
+      final NecessaryAccessorsVisitor visitor = checkNecessaryGettersSetters4ExtractedClass();
       sourceClass.accept(visitor);
       extractedClassBuilder.setFieldsNeedingGetters(visitor.getFieldsNeedingGetter());
       extractedClassBuilder.setFieldsNeedingSetters(visitor.getFieldsNeedingSetter());
@@ -716,7 +770,7 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor {
     return true;
   }
 
-  private class NecessaryAccessorsVisitor extends JavaRecursiveElementWalkingVisitor {
+  private abstract class NecessaryAccessorsVisitor extends JavaRecursiveElementWalkingVisitor {
     private final Set<PsiField> fieldsNeedingGetter = new HashSet<PsiField>();
     private final Set<PsiField> fieldsNeedingSetter = new HashSet<PsiField>();
 
@@ -724,7 +778,7 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor {
       super.visitReferenceExpression(expression);
       if (isProhibitedReference(expression)) {
         final PsiField field = getReferencedField(expression);
-        if (!hasGetter(field) && !isStaticFinal(field)) {
+        if (!hasGetter(field) && !isStaticFinal(field) && !field.getModifierList().hasModifierProperty(PsiModifier.PUBLIC)) {
           fieldsNeedingGetter.add(field);
         }
       }
@@ -742,7 +796,7 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor {
       final PsiExpression lhs = expression.getLExpression();
       if (isProhibitedReference(lhs)) {
         final PsiField field = getReferencedField(lhs);
-        if (!hasGetter(field) && !isStaticFinal(field)) {
+        if (!hasGetter(field) && !isStaticFinal(field) && !field.getModifierList().hasModifierProperty(PsiModifier.PUBLIC)) {
           fieldsNeedingSetter.add(field);
         }
       }
@@ -779,6 +833,15 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor {
       return fieldsNeedingSetter;
     }
 
+    private boolean hasGetter(final PsiField field) {
+      return hasGetterOrSetter(sourceClass.findMethodsBySignature(PropertyUtil.generateGetterPrototype(field), false));
+    }
+
+    private boolean hasSetter(final PsiField field) {
+      return hasGetterOrSetter(sourceClass.findMethodsBySignature(PropertyUtil.generateSetterPrototype(field), false));
+    }
+
+    protected abstract boolean hasGetterOrSetter(final PsiMethod[] getters);
 
     protected boolean isProhibitedReference(PsiExpression expression) {
       return BackpointerUtil.isBackpointerReference(expression, new Condition<PsiField>() {
@@ -788,15 +851,7 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor {
       });
     }
 
-    protected boolean isProhibitedReference(PsiField field) {
-      if (fields.contains(field)) {
-        return false;
-      }
-      if (innerClasses.contains(field.getContainingClass())) {
-        return false;
-      }
-      return true;
-    }
+    protected abstract boolean isProhibitedReference(PsiField field);
 
     private PsiField getReferencedField(PsiExpression expression) {
       if (expression instanceof PsiParenthesizedExpression) {
index a6452a783fd3167b5dc2eb82031f20129f403589..9406473379eac466a660666ba17381b8c2c078af 100644 (file)
@@ -23,19 +23,21 @@ import com.intellij.util.IncorrectOperationException;
 
 public class ReplaceInstanceVariableAccess extends FixableUsageInfo {
     private final PsiReferenceExpression expression;
+    private final String fieldName;
     private final String getterName;
     private final String delegateName;
 
-    public ReplaceInstanceVariableAccess(PsiReferenceExpression expression, String delegateName, String getterName) {
+    public ReplaceInstanceVariableAccess(PsiReferenceExpression expression, String delegateName, String getterName, String name) {
         super(expression);
         this.getterName = getterName;
         this.delegateName = delegateName;
         this.expression = expression;
+        fieldName = name;
     }
 
     public void fixUsage() throws IncorrectOperationException {
         final PsiElement qualifier = expression.getQualifier();
-        final String callString = delegateName + '.' + getterName + "()";
+        final String callString = delegateName + '.' + (getterName != null ? getterName + "()" : fieldName);
         if (qualifier != null) {
             final String qualifierText = qualifier.getText();
             MutationUtils.replaceExpression(qualifierText + '.' + callString, expression);
index 445ead8872aae57794caf834b35f793f746ff547..637251e65b841a1a4f3ba5e5724e356bd111e4c4 100644 (file)
@@ -21,52 +21,74 @@ import com.intellij.refactoring.util.FixableUsageInfo;
 import com.intellij.util.IncorrectOperationException;
 
 public class ReplaceInstanceVariableAssignment extends FixableUsageInfo {
-    private final String setterName;
-    private final PsiAssignmentExpression assignment;
-    private final String getterName;
-    private final String delegateName;
+  private final String setterName;
+  private final PsiAssignmentExpression assignment;
+  private final String getterName;
+  private final String delegateName;
+  private final String fieldName;
 
-    public ReplaceInstanceVariableAssignment(PsiAssignmentExpression assignment,
-                                      String delegateName,
-                                      String setterName,
-                                      String getterName) {
-        super(assignment);
-        this.assignment = assignment;
-        this.getterName = getterName;
-        this.setterName = setterName;
-        this.delegateName = delegateName;
-    }
+  public ReplaceInstanceVariableAssignment(PsiAssignmentExpression assignment,
+                                           String delegateName,
+                                           String setterName,
+                                           String getterName, String name) {
+    super(assignment);
+    this.assignment = assignment;
+    this.getterName = getterName;
+    this.setterName = setterName;
+    this.delegateName = delegateName;
+    fieldName = name;
+  }
 
-    public void fixUsage() throws IncorrectOperationException {
-        final PsiReferenceExpression lhs =
-                (PsiReferenceExpression) assignment.getLExpression();
-        final PsiExpression rhs = assignment.getRExpression();
-        assert rhs != null;
-        final PsiElement qualifier = lhs.getQualifier();
-        final PsiJavaToken sign = assignment.getOperationSign();
-        final String operator = sign.getText();
-        final String rhsText = rhs.getText();
-        final String newExpression;
-        if (qualifier != null) {
-            final String qualifierText = qualifier.getText();
-            if ("=".equals(operator)) {
-                newExpression = qualifierText + '.' + delegateName + '.' + setterName + "( " + rhsText + ')';
-            } else {
-                final String strippedOperator = getStrippedOperator(operator);
-                newExpression = qualifierText + '.'+delegateName + '.' + setterName + '(' + qualifierText + '.'+delegateName + '.' + getterName + "()" + strippedOperator + rhsText + ')';
-            }
-        } else {
-            if ("=".equals(operator)) {
-                newExpression = delegateName + '.' + setterName + "( " + rhsText + ')';
-            } else {
-                final String strippedOperator = getStrippedOperator(operator);
-                newExpression = delegateName + '.' + setterName + '(' + delegateName + '.' + getterName + "()" + strippedOperator + rhsText + ')';
-            }
-        }
-        MutationUtils.replaceExpression(newExpression, assignment);
+  public void fixUsage() throws IncorrectOperationException {
+    final PsiReferenceExpression lhs =
+      (PsiReferenceExpression)assignment.getLExpression();
+    final PsiExpression rhs = assignment.getRExpression();
+    assert rhs != null;
+    final PsiElement qualifier = lhs.getQualifier();
+    final PsiJavaToken sign = assignment.getOperationSign();
+    final String operator = sign.getText();
+    final String rhsText = rhs.getText();
+    final String newExpression;
+    if (qualifier != null) {
+      final String qualifierText = qualifier.getText();
+      if ("=".equals(operator)) {
+        newExpression = qualifierText + '.' + delegateName + '.' + callSetter(rhsText);
+      }
+      else {
+        final String strippedOperator = getStrippedOperator(operator);
+        newExpression = qualifierText +
+                        '.' +
+                        delegateName +
+                        '.' +
+                        callSetter(
+                          qualifierText +
+                          '.' +
+                          delegateName +
+                          '.' +
+                          callGetter() + strippedOperator + rhsText);
+      }
     }
-
-    private static String getStrippedOperator(String operator) {
-        return operator.substring(0, operator.length() - 1);
+    else {
+      if ("=".equals(operator)) {
+        newExpression = delegateName + '.' + callSetter(rhsText);
+      }
+      else {
+        final String strippedOperator = getStrippedOperator(operator);
+        newExpression = delegateName + '.' + callSetter(delegateName + '.' + callGetter() + strippedOperator + rhsText);
+      }
     }
+    MutationUtils.replaceExpression(newExpression, assignment);
+  }
+
+  private String callSetter(String rhsText) {
+    return setterName != null ? setterName + "( " + rhsText + ")" : fieldName + "=" + rhsText;
+  }
+
+  private String callGetter() {
+    return getterName != null ? getterName + "()" : fieldName;
+  }
+
+  private static String getStrippedOperator(String operator) {
+    return operator.substring(0, operator.length() - 1);
+  }
 }
index 8d4fc1fddd359c7ef1d67a53f5148fb735ef2f80..c6417d6f9fafa9365480303af21d03d5429a1bdb 100644 (file)
@@ -20,18 +20,25 @@ import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.refactoring.psi.MutationUtils;
 import com.intellij.refactoring.util.FixableUsageInfo;
 import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.Nullable;
 
 public class ReplaceInstanceVariableIncrementDecrement extends FixableUsageInfo {
   private final PsiExpression reference;
-  private final String setterName;
-  private final String getterName;
+  private final @Nullable String setterName;
+  private final @Nullable String getterName;
   private final String delegateName;
+  private final String fieldName;
 
-  public ReplaceInstanceVariableIncrementDecrement(PsiExpression reference, String delegateName, String setterName, String getterName) {
+  public ReplaceInstanceVariableIncrementDecrement(PsiExpression reference,
+                                                   String delegateName,
+                                                   String setterName,
+                                                   String getterName,
+                                                   String name) {
     super(reference);
     this.getterName = getterName;
     this.setterName = setterName;
     this.delegateName = delegateName;
+    fieldName = name;
     final PsiPrefixExpression prefixExpr = PsiTreeUtil.getParentOfType(reference, PsiPrefixExpression.class);
     if (prefixExpr != null) {
       this.reference = prefixExpr;
@@ -56,31 +63,26 @@ public class ReplaceInstanceVariableIncrementDecrement extends FixableUsageInfo
     final PsiElement qualifier = lhs.getQualifier();
     final String operator = sign.getText();
     final String newExpression;
+    final String strippedOperator = getStrippedOperator(operator);
     if (qualifier != null) {
       final String qualifierText = qualifier.getText();
-      final String strippedOperator = getStrippedOperator(operator);
-      newExpression = qualifierText +
-                      '.' +
-                      delegateName +
-                      '.' +
-                      setterName +
-                      '(' +
-                      qualifierText +
-                      '.' +
-                      delegateName +
-                      '.' +
-                      getterName +
-                      "()" +
-                      strippedOperator +
-                      "1)";
+      newExpression = qualifierText + '.' + delegateName + '.' +
+                      callSetter(qualifierText + '.' + delegateName + '.' + callGetter() + strippedOperator + "1");
     }
     else {
-      final String strippedOperator = getStrippedOperator(operator);
-      newExpression = delegateName + '.' + setterName + '(' + delegateName + '.' + getterName + "()" + strippedOperator + "1)";
+      newExpression = delegateName + '.' + callSetter(delegateName + '.' + callGetter() + strippedOperator + "1");
     }
     MutationUtils.replaceExpression(newExpression, reference);
   }
 
+  private String callGetter() {
+    return (getterName != null ? getterName + "()" : fieldName);
+  }
+
+  private String callSetter(String rhsText) {
+    return setterName != null ? setterName + "(" + rhsText + ")" : fieldName + "=" + rhsText;
+  }
+
   private static String getStrippedOperator(String operator) {
     return operator.substring(0, operator.length() - 1);
   }
index 237387fac73722146ca67b1cf4fa8a0ae8246175..9e842d7bccb73c3ee846dc003a132fb8d8801770 100644 (file)
@@ -186,7 +186,7 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
   }
 
   protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
-    UsageInfo[] usagesIn = refUsages.get();
+    final UsageInfo[] usagesIn = refUsages.get();
     ArrayList<UsageInfo> oldUsages = new ArrayList<UsageInfo>();
     addAll(oldUsages, usagesIn);
     final ObjectUpcastedUsageInfo[] objectUpcastedUsageInfos = objectUpcastedUsages(usagesIn);
@@ -202,7 +202,11 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
       analyzeConflicts(usagesIn, conflicts);
       if (!conflicts.isEmpty()) {
         ConflictsDialog conflictsDialog =
-                new ConflictsDialog(myProject, conflicts);
+          new ConflictsDialog(myProject, conflicts, new Runnable() {
+            public void run() {
+              execute(usagesIn);
+            }
+          });
         conflictsDialog.show();
         if (!conflictsDialog.isOK()){
           if (conflictsDialog.isShowConflicts()) prepareSuccessful();
index 186b5f0c3cbb25d4e8c1f352421198b78e53a411..0cc343e57b593cc5a6cc60a19de0541fe71470b9 100644 (file)
@@ -228,7 +228,7 @@ class InlineConstantFieldProcessor extends BaseRefactoringProcessor {
       }
     }
 
-    return showConflicts(conflicts);
+    return showConflicts(conflicts, usagesIn);
   }
 
   private static boolean isAccessedForWriting (PsiExpression expr) {
index 7ad18b79a276eeb7c149493636b13470af0da391..09c9382485c7fac60f321fa22336fccd7442c0d6 100644 (file)
  */
 package com.intellij.refactoring.inline;
 
+import com.intellij.codeInsight.TargetElementUtilBase;
 import com.intellij.codeInsight.highlighting.HighlightManager;
 import com.intellij.codeInsight.intention.QuickFixFactory;
-import com.intellij.codeInsight.TargetElementUtilBase;
-import com.intellij.lang.refactoring.InlineActionHandler;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.command.CommandProcessor;
 import com.intellij.openapi.diagnostic.Logger;
@@ -166,7 +165,7 @@ public class InlineLocalHandler extends JavaInlineActionHandler {
       }
     }
 
-    if (checkRefsInAugmentedAssignment(refsToInline, project, editor, localName)) {
+    if (checkRefsInAugmentedAssignmentOrUnaryModified(refsToInline, project, editor, localName)) {
       return;
     }
 
@@ -238,21 +237,26 @@ public class InlineLocalHandler extends JavaInlineActionHandler {
     }, RefactoringBundle.message("inline.command", localName), null);
   }
 
-  private static boolean checkRefsInAugmentedAssignment(final PsiElement[] refsToInline, final Project project, final Editor editor,
+  private static boolean checkRefsInAugmentedAssignmentOrUnaryModified(final PsiElement[] refsToInline, final Project project, final Editor editor,
                                                         final String localName) {
-    for(PsiElement element: refsToInline) {
-      if (element.getParent() instanceof PsiAssignmentExpression) {
-        PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression) element.getParent();
-        if (element == assignmentExpression.getLExpression()) {
-          EditorColorsManager manager = EditorColorsManager.getInstance();
-          final TextAttributes writeAttributes = manager.getGlobalScheme().getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES);
-          HighlightManager.getInstance(project).addOccurrenceHighlights(editor, new PsiElement[]{element}, writeAttributes, true, null);
-
-          String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("variable.is.accessed.for.writing", localName));
-          CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.INLINE_VARIABLE);
-          WindowManager.getInstance().getStatusBar(project).setInfo(RefactoringBundle.message("press.escape.to.remove.the.highlighting"));
-          return true;
-        }
+    for (PsiElement element : refsToInline) {
+
+      PsiElement parent = element.getParent();
+      if (parent instanceof PsiArrayAccessExpression) {
+        element = parent;
+        parent = parent.getParent();
+      }
+
+      if (parent instanceof PsiAssignmentExpression && element == ((PsiAssignmentExpression)parent).getLExpression() ||
+          parent instanceof PsiPrefixExpression || parent instanceof PsiPostfixExpression ) {
+
+        EditorColorsManager manager = EditorColorsManager.getInstance();
+        final TextAttributes writeAttributes = manager.getGlobalScheme().getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES);
+        HighlightManager.getInstance(project).addOccurrenceHighlights(editor, new PsiElement[]{element}, writeAttributes, true, null);
+        String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("variable.is.accessed.for.writing", localName));
+        CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.INLINE_VARIABLE);
+        WindowManager.getInstance().getStatusBar(project).setInfo(RefactoringBundle.message("press.escape.to.remove.the.highlighting"));
+        return true;
       }
     }
     return false;
index c714bf0a381ba3eef1b0dbae6e148c3e5f99596e..3773594dc84727434c406f08ada36282fc885d82 100644 (file)
@@ -141,7 +141,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
     if (!myInlineThisOnly) {
       if (!CommonRefactoringUtil.checkReadOnlyStatus(myProject, myMethod)) return false;
     }
-    return showConflicts(conflicts);
+    return showConflicts(conflicts, usagesIn);
   }
 
   private void addInaccessibleSuperCallsConflicts(final UsageInfo[] usagesIn, final MultiMap<PsiElement, String> conflicts) {
@@ -725,18 +725,31 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
           parent = parent.getParent();
         }
         if (parent instanceof PsiClass) {
-          final PsiClass parentClass = (PsiClass)parent;
+          PsiClass parentClass = (PsiClass)parent;
           final PsiClass containingClass = myMethod.getContainingClass();
           if (InheritanceUtil.isInheritorOrSelf(parentClass, containingClass, true)) {
             qualifier = myFactory.createExpressionFromText("this", null);
           }
           else {
-            String name = containingClass.getName();
-            if (name != null) {
-              qualifier = myFactory.createExpressionFromText(name + ".this", null);
-            }
-            else { //?
-              qualifier = myFactory.createExpressionFromText("this", null);
+            if (PsiTreeUtil.isAncestor(containingClass, parent, false)) {
+              String name = containingClass.getName();
+              if (name != null) {
+                qualifier = myFactory.createExpressionFromText(name + ".this", null);
+              }
+              else { //?
+                qualifier = myFactory.createExpressionFromText("this", null);
+              }
+            } else { // we are inside the inheritor
+              do {
+                parentClass = PsiTreeUtil.getParentOfType(parentClass, PsiClass.class, true);
+                if (InheritanceUtil.isInheritorOrSelf(parentClass, containingClass, true)) {
+                  LOG.assertTrue(parentClass != null);
+                  final String childClassName = parentClass.getName();
+                  qualifier = myFactory.createExpressionFromText(childClassName != null ? childClassName + ".this" : "this", null);
+                  break;
+                }
+              }
+              while (parentClass != null);
             }
           }
         }
@@ -1103,7 +1116,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
           PsiClassInitializer classInitializer = myFactory.createClassInitializer();
           final PsiClass containingClass = field.getContainingClass();
           classInitializer = (PsiClassInitializer)containingClass.addAfter(classInitializer, field);
-          containingClass.addAfter(CodeEditUtil.createLineFeed(field.getManager()), field);          
+          containingClass.addAfter(CodeEditUtil.createLineFeed(field.getManager()), field);
           final PsiCodeBlock body = classInitializer.getBody();
           PsiExpressionStatement statement = (PsiExpressionStatement)myFactory.createStatementFromText(field.getName() + " = 0;", body);
           statement = (PsiExpressionStatement)body.add(statement);
index 19ab41026c2c6e21e046f08fc42aea4633bd81c0..d4cf4bdffa09f52571c7d02ea70ff1669d953cb7 100644 (file)
@@ -205,7 +205,7 @@ public class InlineParameterExpressionProcessor extends BaseRefactoringProcessor
         }
       }
     }
-    return showConflicts(conflicts);
+    return showConflicts(conflicts, usages);
   }
 
   private static boolean isAccessedForWriting (PsiExpression expr) {
index 21940971ba969494f5f785f16e923c9e303e6a52..574c18398b213328759b03613312e6dd8e336803 100644 (file)
@@ -128,7 +128,7 @@ public class InlineToAnonymousClassProcessor extends BaseRefactoringProcessor {
   protected boolean preprocessUsages(final Ref<UsageInfo[]> refUsages) {
     MultiMap<PsiElement, String> conflicts = getConflicts(refUsages.get());
     if (!conflicts.isEmpty()) {
-      return showConflicts(conflicts);
+      return showConflicts(conflicts, refUsages.get());
     }
     return super.preprocessUsages(refUsages);
   }
index 112b86ba4ed947ac274d4799e5aad49c3214e5db..50f24d095af908dbd7d3f1cad967a447846a101a 100644 (file)
@@ -201,14 +201,14 @@ public class InlineSuperClassRefactoringProcessor extends FixableUsagesRefactori
       conflicts.put(element, conflictsMap.get(element));
     }
     checkConflicts(refUsages, conflicts);
-    return showConflicts(conflicts);
+    return showConflicts(conflicts, refUsages.get());
   }
 
   protected void performRefactoring(final UsageInfo[] usages) {
     new PushDownProcessor(mySuperClass.getProject(), myMemberInfos, mySuperClass, new DocCommentPolicy(DocCommentPolicy.ASIS)){
       //push down conflicts are already collected
       @Override
-      protected boolean showConflicts(MultiMap<PsiElement, String> conflicts) {
+      protected boolean showConflicts(MultiMap<PsiElement, String> conflicts, UsageInfo[] usages) {
         return true;
       }
     }.run();
index 26f2a212b2047197fc73a54bf46558b44341286f..128fd029fc89de17f2f62d6132f5db1e4cb1b921 100644 (file)
@@ -79,9 +79,16 @@ public class ElementToWorkOn {
 
         final int offset = editor.getCaretModel().getOffset();
         final PsiElement[] statementsInRange = IntroduceVariableBase.findStatementsAtOffset(editor, file, offset);
+
         if (statementsInRange.length == 1 && PsiUtil.hasErrorElementChild(statementsInRange[0])) {
           editor.getSelectionModel().selectLineAtCaret();
-        } else {
+          final ElementToWorkOn elementToWorkOn = getElementToWorkOn(editor, file, refactoringName, helpId, project, localVar, expr);
+          if (elementToWorkOn == null || elementToWorkOn.getLocalVariable() == null && elementToWorkOn.getExpression() == null) {
+            editor.getSelectionModel().removeSelection();
+          }
+        }
+
+        if (!editor.getSelectionModel().hasSelection()){
           final List<PsiExpression> expressions = IntroduceVariableBase.collectExpressions(file, editor, offset, statementsInRange);
           if (expressions.isEmpty()) {
             editor.getSelectionModel().selectLineAtCaret();
index 0ae7342287fded6bbcaf94b2cb0b5afc43bbd2b3..c21a50c78698236716691c924eacf9ee5b6afd64 100644 (file)
@@ -243,7 +243,7 @@ public class IntroduceParameterProcessor extends BaseRefactoringProcessor implem
       processor.findConflicts(this, refUsages.get(), conflicts);
     }
 
-    return showConflicts(conflicts);
+    return showConflicts(conflicts, usagesIn);
   }
 
   private void detectAccessibilityConflicts(final UsageInfo[] usageArray, MultiMap<PsiElement, String> conflicts) {
index d536914a553e27579cf40eb3d1b0ae23289d8ad6..525aefe0131970358126486bea48c6923a4772f1 100644 (file)
@@ -77,18 +77,26 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme
   protected static String REFACTORING_NAME = RefactoringBundle.message("introduce.variable.title");
 
   public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file, DataContext dataContext) {
-    if (!editor.getSelectionModel().hasSelection()) {
+    final SelectionModel selectionModel = editor.getSelectionModel();
+    if (!selectionModel.hasSelection()) {
       final int offset = editor.getCaretModel().getOffset();
       final PsiElement[] statementsInRange = findStatementsAtOffset(editor, file, offset);
+
+      //try line selection
       if (statementsInRange.length == 1 && (PsiUtil.hasErrorElementChild(statementsInRange[0]) || isPreferStatements())) {
-        editor.getSelectionModel().selectLineAtCaret();
-      } else {
+        selectionModel.selectLineAtCaret();
+        if (findExpressionInRange(project, file, selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()) == null) {
+          selectionModel.removeSelection();
+        }
+      }
+
+      if (!selectionModel.hasSelection()) {
         final List<PsiExpression> expressions = collectExpressions(file, editor, offset, statementsInRange);
         if (expressions.isEmpty()) {
-          editor.getSelectionModel().selectLineAtCaret();
+          selectionModel.selectLineAtCaret();
         } else if (expressions.size() == 1) {
           final TextRange textRange = expressions.get(0).getTextRange();
-          editor.getSelectionModel().setSelection(textRange.getStartOffset(), textRange.getEndOffset());
+          selectionModel.setSelection(textRange.getStartOffset(), textRange.getEndOffset());
         }
         else {
           showChooser(editor, expressions, new Pass<PsiExpression>(){
@@ -100,8 +108,8 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme
         }
       }
     }
-    if (invoke(project, editor, file, editor.getSelectionModel().getSelectionStart(), editor.getSelectionModel().getSelectionEnd())) {
-      editor.getSelectionModel().removeSelection();
+    if (invoke(project, editor, file, selectionModel.getSelectionStart(), selectionModel.getSelectionEnd())) {
+      selectionModel.removeSelection();
     }
   }
 
@@ -224,6 +232,10 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme
     PsiDocumentManager.getInstance(project).commitAllDocuments();
 
 
+    return invokeImpl(project, findExpressionInRange(project, file, startOffset, endOffset), editor);
+  }
+
+  private static PsiExpression findExpressionInRange(Project project, PsiFile file, int startOffset, int endOffset) {
     PsiExpression tempExpr = CodeInsightUtil.findExpressionInRange(file, startOffset, endOffset);
     if (tempExpr == null) {
       PsiElement[] statements = CodeInsightUtil.findStatementsInRange(file, startOffset, endOffset);
@@ -239,7 +251,7 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme
     if (tempExpr == null) {
       tempExpr = getSelectedExpression(project, file, startOffset, endOffset);
     }
-    return invokeImpl(project, tempExpr, editor);
+    return tempExpr;
   }
 
   public static PsiExpression getSelectedExpression(final Project project, final PsiFile file, final int startOffset, final int endOffset) {
index c500088896097b050096cd98ad47d3f76e2a702a..d89efed1e11118b2142bee7d87d55e6a1e4b8e76 100644 (file)
@@ -149,7 +149,7 @@ public class IntroduceParameterObjectProcessor extends FixableUsagesRefactoringP
         }
       }
     }
-    return showConflicts(conflicts);
+    return showConflicts(conflicts, refUsages.get());
   }
 
   public void findUsages(@NotNull List<FixableUsageInfo> usages) {
index e034af55c99d36b5bbcf6102de5784e716d1f16a..5c5036683675e1678e46f9a8eec435652157b7e2 100644 (file)
@@ -70,12 +70,16 @@ public abstract class MakeMethodOrClassStaticProcessor<T extends PsiTypeParamete
     return new MakeMethodOrClassStaticViewDescriptor(myMember);
   }
 
-  protected final boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
+  protected final boolean preprocessUsages(final Ref<UsageInfo[]> refUsages) {
     UsageInfo[] usagesIn = refUsages.get();
     if (myPrepareSuccessfulSwingThreadCallback != null) {
       MultiMap<PsiElement, String> conflicts = getConflictDescriptions(usagesIn);
       if (conflicts.size() > 0) {
-        ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
+        ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts, new Runnable(){
+          public void run() {
+            execute(refUsages.get());
+          }
+        });
         conflictsDialog.show();
         if (!conflictsDialog.isOK()) {
           if (conflictsDialog.isShowConflicts()) prepareSuccessful();
index 0edd3a3228c912d0005f640589578b7caf65be68..6aa631de9748d6c54b594fb2665ba12481b98516 100644 (file)
@@ -104,7 +104,7 @@ public class PushDownProcessor extends BaseRefactoringProcessor {
           myCreateClassDlg = CreateSubclassAction.chooseSubclassToCreate(myClass);
           if (myCreateClassDlg != null) {
             pushDownConflicts.checkTargetClassConflicts(null, false, myCreateClassDlg.getTargetDirectory());
-            return showConflicts(pushDownConflicts.getConflicts());
+            return showConflicts(pushDownConflicts.getConflicts(), usagesIn);
           } else {
             return false;
           }
@@ -118,7 +118,7 @@ public class PushDownProcessor extends BaseRefactoringProcessor {
       }
     }
 
-    return showConflicts(pushDownConflicts.getConflicts());
+    return showConflicts(pushDownConflicts.getConflicts(), usagesIn);
   }
 
   protected void refreshElements(PsiElement[] elements) {
@@ -149,7 +149,7 @@ public class PushDownProcessor extends BaseRefactoringProcessor {
       removeFromTargetClass();
     }
     catch (IncorrectOperationException e) {
-      LOG.assertTrue(false);
+      LOG.error(e);
     }
   }
 
index d6728cb2224c9c61efd0d5a31fdd4994f5e00538..371409623bdda0a5522c696a4c53b25b74c1ace7 100644 (file)
@@ -109,7 +109,8 @@ public class MoveClassToInnerProcessor extends BaseRefactoringProcessor {
   }
 
   protected boolean preprocessUsages(final Ref<UsageInfo[]> refUsages) {
-    return showConflicts(getConflicts(refUsages.get()));
+    final UsageInfo[] usages = refUsages.get();
+    return showConflicts(getConflicts(usages), usages);
   }
 
   protected void refreshElements(final PsiElement[] elements) {
index aa68369253e2a8d9686f18a9ffe2474aa3709246..55840bff429737249bda5ec21ca28fd65b400413 100644 (file)
@@ -204,7 +204,7 @@ public class MoveClassesOrPackagesProcessor extends BaseRefactoringProcessor {
     }
 
     refUsages.set(filteredUsages.toArray(new UsageInfo[filteredUsages.size()]));
-    return showConflicts(conflicts);
+    return showConflicts(conflicts, usages);
   }
 
   private boolean isInsideMoved(PsiElement place) {
index 9ebfaada25bfcea04d89fa7bfcddfeb350fc50d4..973f212d22e0255cc3f0e8cb94ba3c917ef63cf5 100644 (file)
@@ -146,7 +146,7 @@ public class MoveDirectoryWithClassesProcessor extends BaseRefactoringProcessor
         conflicts.putValue(psiFile, e.getMessage());
       }
     }
-    return showConflicts(conflicts);
+    return showConflicts(conflicts, refUsages.get());
   }
 
   @Override
index d4ef7978342de2947a8fb96e6e7e6d2d1688bd5c..21662cf5cb64ba6ccc3cb5b52d706186be5f496f 100644 (file)
@@ -403,7 +403,7 @@ public class MoveInnerProcessor extends BaseRefactoringProcessor {
 //    if (myInnerClass.hasModifierProperty(PsiModifier.)) {
     myOuterClass.accept(new Visitor());
 
-    return showConflicts(conflicts);
+    return showConflicts(conflicts, refUsages.get());
   }
 
   private static boolean isInPackage(final PsiFile containingFile, PsiPackage aPackage) {
index 6cd4d13f11114219702c080d09a46bc8231e2e5a..a67d424c2c3cd89bb2a529edd3db932e355f2e8e 100644 (file)
@@ -127,7 +127,7 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{
     }
     catch (IncorrectOperationException e) {}
 
-    return showConflicts(conflicts);
+    return showConflicts(conflicts, usages);
   }
 
   @NotNull
index 56dc68aa0b10a28e65a25df6ec43234f8d382314..2852d5b6144c82ba0534d42d5a652361eef940de 100644 (file)
@@ -242,7 +242,7 @@ public class MoveMembersProcessor extends BaseRefactoringProcessor {
     }
     analyzeMoveConflicts(myMembersToMove, myTargetClass, myNewVisibility, conflicts);
     RefactoringConflictsUtil.analyzeModuleConflicts(myProject, myMembersToMove, usages, myTargetClass, conflicts);
-    return showConflicts(conflicts);
+    return showConflicts(conflicts, usages);
   }
 
   private void addInaccessiblleConflicts(final MultiMap<PsiElement, String> conflicts, final UsageInfo[] usages) throws IncorrectOperationException {
index 584cc4475ec33654fe5fff0fdde06f1289c1e4b8..5ec1420e766381b4aed8031ce3000b41be609fab 100644 (file)
@@ -84,7 +84,7 @@ public class RemoveMiddlemanProcessor extends FixableUsagesRefactoringProcessor
         }
       }
     }
-    return showConflicts(conflicts);
+    return showConflicts(conflicts, refUsages.get());
   }
 
   private void processUsagesForMethod(final boolean deleteMethodHierarchy, PsiMethod method, int[] paramPermutation, String getterName, PsiMethod delegatedMethod,
index 95ef48dff71822febc368fb96e15ac088329a4c9..30f404a01a7f6a7fca0b07b13a71b5e89ba9ccc5 100644 (file)
@@ -176,7 +176,7 @@ public class ReplaceConstructorWithBuilderProcessor extends FixableUsagesRefacto
         type = ((PsiEllipsisType)type).toArrayType();
       }
       field = myElementFactory.createField(parameterData.getFieldName(), type);
-      builderClass.add(field);
+      field = (PsiField)builderClass.add(field);
     }
 
     final String defaultValue = parameterData.getDefaultValue();
@@ -285,7 +285,7 @@ public class ReplaceConstructorWithBuilderProcessor extends FixableUsagesRefacto
       conflicts.putValue(null, "Found constructors are not reducible to simple chain");
     }
 
-    return showConflicts(conflicts);
+    return showConflicts(conflicts, refUsages.get());
   }
 
   protected String getCommandName() {
index 63cc01f214347b0c08b066136a120384bce56e68..b81fa745bf332aecf270e97327e98ad611d82105 100644 (file)
@@ -172,7 +172,7 @@ public class ReplaceConstructorWithFactoryProcessor extends BaseRefactoringProce
     }
 
 
-    return showConflicts(conflicts);
+    return showConflicts(conflicts, usages);
   }
 
   private PsiClass getConstructorContainingClass() {
index 564e16cc7adf7f4f7163647d1ef4dfd08f42636e..0b59f205de749a9b83ee1be4d59ee0d141f802f2 100644 (file)
@@ -228,7 +228,7 @@ public class WrapReturnValueProcessor extends FixableUsagesRefactoringProcessor
         conflicts.putValue(existingClass, RefactorJBundle.message("there.already.exists.a.class.with.the.selected.name"));
       }
     }
-    return showConflicts(conflicts);
+    return showConflicts(conflicts, refUsages.get());
   }
 
   protected void performRefactoring(UsageInfo[] usageInfos) {
diff --git a/java/java-tests/testData/refactoring/extractClass/multipleGetters/after/Extracted.java b/java/java-tests/testData/refactoring/extractClass/multipleGetters/after/Extracted.java
deleted file mode 100644 (file)
index 8d19541..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-public class Extracted {
-    int myT;
-
-    public Extracted() {
-    }
-}
\ No newline at end of file
index d5b28e57d91eda70469753d1b73f2b4785a1bae4..7ae85c85a278bc85f6551fad6ee671db3a060f6e 100644 (file)
@@ -1,10 +1,9 @@
 class Test {
-    final Extracted extracted = new Extracted();
-
-    public int getMyT() {
-    return extracted.getMyT();
+  int myT;
+  public int getMyT() {
+    return myT;
   }
   void bar(){
-    int i = extracted.getMyT();
+    int i = myT;
   }
 }
\ No newline at end of file
index adfd3779e3d64e9f5c56e9e8020fe5ddb83e829e..61c59fccd50ce27c3d60b14003810ec16cce8fdf 100644 (file)
@@ -3,6 +3,6 @@ class Test<T> {
 
     void foo(T t){}
   void bar(){
-    foo(extracted.getMyT());
+    foo(extracted.myT);
   }
 }
\ No newline at end of file
diff --git a/java/java-tests/testData/refactoring/inlineMethod/MethodCallInOtherAnonymousOrInner.java b/java/java-tests/testData/refactoring/inlineMethod/MethodCallInOtherAnonymousOrInner.java
new file mode 100644 (file)
index 0000000..a38a62d
--- /dev/null
@@ -0,0 +1,23 @@
+public class Parent {
+  void execute(){}
+  void foo<caret>execute(){
+    execute();
+  }
+}
+
+class Child extends Parent {
+  void foo() {
+    fooexecute();
+    new Runnable() {
+      public void run() {
+        fooexecute();
+      }
+    }.run();
+  }
+
+  class InnerChild {
+    void bar() {
+      Child.this.fooexecute();
+    }
+  }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/refactoring/inlineMethod/MethodCallInOtherAnonymousOrInner.java.after b/java/java-tests/testData/refactoring/inlineMethod/MethodCallInOtherAnonymousOrInner.java.after
new file mode 100644 (file)
index 0000000..b71aca1
--- /dev/null
@@ -0,0 +1,20 @@
+public class Parent {
+  void execute(){}
+}
+
+class Child extends Parent {
+  void foo() {
+      execute();
+      new Runnable() {
+      public void run() {
+          execute();
+      }
+    }.run();
+  }
+
+  class InnerChild {
+    void bar() {
+        execute();
+    }
+  }
+}
\ No newline at end of file
index dd3e52b81d9a069c25cc4f675e1db257dc73be83..7395f964d7f9f7d665108e2d7df9855722a1b94d 100644 (file)
@@ -1,5 +1,5 @@
 public class Builder {
-    private int i;
+    private int i = 2;
 
     public Builder setI(int i) {
         this.i = i;
index c623e42d40f51ba086be6e7632e0e7c6d7203a1b..d15e92dad608ba2214ac7444b9aa07c3e7b7b5c0 100644 (file)
@@ -1,14 +1,22 @@
 package com.intellij;
 
 import com.intellij.openapi.application.PathManager;
+import com.intellij.testFramework.TestRunnerUtil;
+import junit.framework.TestCase;
 import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.Nullable;
 
 import java.io.File;
+import java.util.*;
+
+import static com.intellij.openapi.util.io.FileUtil.toSystemDependentName;
+import static java.util.Arrays.asList;
 
 /**
  * @author yole
  */
 public class JavaTestUtil {
+
   @NonNls private static final String JAVA_TEST_DATA = "java/java-tests/testData";
 
   public static String getJavaTestDataPath() {
@@ -19,4 +27,115 @@ public class JavaTestUtil {
     }
     return new File(homePath, JAVA_TEST_DATA).getPath();
   }
+
+  private enum TestGroup {
+    ULTIMATE, COMMUNITY
+  }
+
+  /**
+   * It's assumed that test data location for both <code>community</code> and <code>ultimate</code> tests follows the same template:
+   * <code>'<IDEA_HOME>/<RELATIVE_PATH>'</code>.
+   * <p/>
+   * <code>'IDEA_HOME'</code> here stands for path to IDEA installation; <code>'RELATIVE_PATH'</code> defines a path to
+   * test data relative to IDEA installation path. That relative path may be different for <code>community</code>
+   * and <code>ultimate</code> tests.
+   * <p/>
+   * This collection contains mappings from test group type to relative paths to use, i.e. it's possible to define more than one
+   * relative path for the single test group. It's assumed that path definition algorithm iterates them and checks if
+   * resulting absolute path points to existing directory. The one is returned in case of success; last path is returned otherwise.
+   * <p/>
+   * Hence, the order of relative paths for the single test group matters.
+   */
+  private static final Map<TestGroup, List<String>> TEST_DATA_RELATIVE_PATHS = new EnumMap<TestGroup, List<String>>(TestGroup.class);
+  static {
+    TEST_DATA_RELATIVE_PATHS.put(TestGroup.ULTIMATE, Collections.singletonList(toSystemDependentName("/testData")));
+
+    List<String> communityPathEndings = new ArrayList<String>();
+    String communityEnding = toSystemDependentName("java/java-tests/testData");
+    communityPathEndings.add(toSystemDependentName("community/" + communityEnding));
+    communityPathEndings.add(communityEnding);
+    TEST_DATA_RELATIVE_PATHS.put(TestGroup.COMMUNITY, communityPathEndings);
+  }
+
+  private JavaTestUtil() {
+  }
+
+  @NonNls
+  public static String getJavaTestDataPath2() {
+    String homePath = PathManager.getHomePath();
+    TestGroup testGroup = determineTestGroup();
+    List<String> relativePaths = TEST_DATA_RELATIVE_PATHS.get(testGroup);
+    if (relativePaths.isEmpty()) {
+      throw new IllegalStateException(
+        String.format("Can't determine test data path. Reason: no predefined relative paths are configured for test group %s. "
+                      + "Configured mappings: %s", testGroup, TEST_DATA_RELATIVE_PATHS)
+      );
+    }
+
+    File candidate = null;
+    for (String relativePath : relativePaths) {
+      candidate = new File(homePath, relativePath);
+      if (candidate.isDirectory()) {
+        return candidate.getPath();
+      }
+    }
+
+    if (candidate == null) {
+      throw new IllegalStateException("Can't determine test data path. Looks like programming error - reached 'if' block that was "
+                                      + "never expected to be executed");
+    }
+    return candidate.getPath();
+  }
+
+  @SuppressWarnings({"ThrowableInstanceNeverThrown"})
+  private static TestGroup determineTestGroup() {
+    for (StackTraceElement stackTraceElement : new Exception().getStackTrace()) {
+      Class<?> clazz = loadClass(stackTraceElement.getClassName());
+      if (isJUnitClass(clazz)) {
+        return determineTestGroup(clazz);
+      }
+    }
+    return TestGroup.ULTIMATE;
+  }
+
+  private static Class<?> loadClass(String className) {
+    Class<?> clazz = null;
+    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+    ClassLoader definingClassLoader = JavaTestUtil.class.getClassLoader();
+    ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
+
+    List<ClassLoader> classLoaders = asList(contextClassLoader, definingClassLoader, systemClassLoader);
+    for (ClassLoader classLoader : classLoaders) {
+      clazz = loadClass(className, classLoader);
+      if (clazz != null) {
+        break;
+      }
+    }
+
+    if (clazz == null) {
+      throw new IllegalStateException(String.format("Can't load class '%s'. Tried to do that via thread context class loader(%s), "
+                                                    + "defining class loader(%s) and system class loader(%s)",
+                                                    className, contextClassLoader, definingClassLoader, systemClassLoader));
+    }
+    return clazz;
+  }
+
+  @Nullable
+  private static Class<?> loadClass(String className, ClassLoader classLoader) {
+    try {
+      return Class.forName(className, true, classLoader);
+    }
+    catch (ClassNotFoundException e) {
+      return null;
+    }
+  }
+
+  private static boolean isJUnitClass(Class<?> clazz) {
+    return TestCase.class.isAssignableFrom(clazz) || TestRunnerUtil.isJUnit4TestClass(clazz);
+  }
+
+  public static TestGroup determineTestGroup(Class<?> clazz) {
+    String rootPath = PathManager.getResourceRoot(clazz, toSystemDependentName(clazz.getName().replace('.', '/') + ".class"));
+    return rootPath != null && rootPath.indexOf("community") >= 0 ? TestGroup.COMMUNITY : TestGroup.ULTIMATE;
+  }
 }
diff --git a/java/java-tests/testSrc/com/intellij/psi/formatter/AbstractJavaFormattingTest.java b/java/java-tests/testSrc/com/intellij/psi/formatter/AbstractJavaFormattingTest.java
new file mode 100644 (file)
index 0000000..2301f40
--- /dev/null
@@ -0,0 +1,164 @@
+/*
+ * Copyright 2000-2010 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.psi.formatter;
+
+import com.intellij.JavaTestUtil;
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.command.CommandProcessor;
+import com.intellij.openapi.editor.Document;
+import com.intellij.openapi.editor.EditorFactory;
+import com.intellij.openapi.editor.ex.DocumentEx;
+import com.intellij.openapi.editor.impl.DocumentImpl;
+import com.intellij.openapi.util.TextRange;
+import com.intellij.openapi.util.io.FileUtil;
+import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.psi.PsiDocumentManager;
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.codeStyle.CodeStyleManager;
+import com.intellij.psi.codeStyle.CodeStyleSettings;
+import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
+import com.intellij.testFramework.LightIdeaTestCase;
+import com.intellij.util.IncorrectOperationException;
+
+import java.io.File;
+
+/**
+ * Base class for java formatter tests that holds utility methods.
+ *
+ * @author Denis Zhdanov
+ * @since Apr 27, 2010 6:26:29 PM
+ */
+public abstract class AbstractJavaFormattingTest extends LightIdeaTestCase {
+
+  private static final String BASE_PATH = JavaTestUtil.getJavaTestDataPath() + "/psi/formatter/java";
+
+  public TextRange myTextRange;
+  public TextRange myLineRange;
+
+  public static CodeStyleSettings getSettings() {
+    return CodeStyleSettingsManager.getSettings(getProject());
+  }
+
+  public void doTest() throws Exception {
+    doTest(getTestName(false) + ".java", getTestName(false) + "_after.java");
+  }
+
+  public void doTest(String fileNameBefore, String fileNameAfter) throws Exception {
+    doTextTest(loadFile(fileNameBefore), loadFile(fileNameAfter));
+  }
+
+  public void doTextTest(final String text, String textAfter) throws IncorrectOperationException {
+    final PsiFile file = createPseudoPhysicalFile("A.java", text);
+
+    if (myLineRange != null) {
+      final DocumentImpl document = new DocumentImpl(text);
+      myTextRange =
+        new TextRange(document.getLineStartOffset(myLineRange.getStartOffset()), document.getLineEndOffset(myLineRange.getEndOffset()));
+    }
+
+    /*
+    CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
+      public void run() {
+        ApplicationManager.getApplication().runWriteAction(new Runnable() {
+          public void run() {
+            performFormatting(file);
+          }
+        });
+      }
+    }, null, null);
+
+    assertEquals(prepareText(textAfter), prepareText(file.getText()));
+
+
+    */
+
+    final PsiDocumentManager manager = PsiDocumentManager.getInstance(getProject());
+    final Document document = manager.getDocument(file);
+
+
+    CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
+      public void run() {
+        ApplicationManager.getApplication().runWriteAction(new Runnable() {
+          public void run() {
+            document.replaceString(0, document.getTextLength(), text);
+            manager.commitDocument(document);
+            try {
+              if (myTextRange != null) {
+                CodeStyleManager.getInstance(getProject()).reformatText(file, myTextRange.getStartOffset(), myTextRange.getEndOffset());
+              }
+              else {
+                CodeStyleManager.getInstance(getProject())
+                  .reformatText(file, file.getTextRange().getStartOffset(), file.getTextRange().getEndOffset());
+              }
+            }
+            catch (IncorrectOperationException e) {
+              assertTrue(e.getLocalizedMessage(), false);
+            }
+          }
+        });
+      }
+    }, "", "");
+
+
+    if (document == null) {
+      fail("Don't expect the document to be null");
+      return;
+    }
+    assertEquals(prepareText(textAfter), prepareText(document.getText()));
+    manager.commitDocument(document);
+    assertEquals(prepareText(textAfter), prepareText(file.getText()));
+
+  }
+
+  public void doMethodTest(final String before, final String after) throws Exception {
+    doTextTest("class Foo{\n" + "    void foo() {\n" + before + '\n' + "    }\n" + "}",
+               "class Foo {\n" + "    void foo() {\n" + StringUtil.shiftIndentInside(after, 8, false) + '\n' + "    }\n" + "}");
+  }
+
+  public void doClassTest(final String before, final String after) throws Exception {
+    doTextTest("class Foo{\n" + before + '\n' + "}", "class Foo {\n" + StringUtil.shiftIndentInside(after, 4, false) + '\n' + "}");
+  }
+
+  private static String prepareText(String actual) {
+    if (actual.startsWith("\n")) {
+      actual = actual.substring(1);
+    }
+    if (actual.startsWith("\n")) {
+      actual = actual.substring(1);
+    }
+
+    // Strip trailing spaces
+    final Document doc = EditorFactory.getInstance().createDocument(actual);
+    CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
+      public void run() {
+        ApplicationManager.getApplication().runWriteAction(new Runnable() {
+          public void run() {
+            ((DocumentEx)doc).stripTrailingSpaces(false);
+          }
+        });
+      }
+    }, "formatting", null);
+
+    return doc.getText();
+  }
+
+  private static String loadFile(String name) throws Exception {
+    String fullName = BASE_PATH + File.separatorChar + name;
+    String text = new String(FileUtil.loadFileText(new File(fullName)));
+    text = StringUtil.convertLineSeparators(text);
+    return text;
+  }
+}
diff --git a/java/java-tests/testSrc/com/intellij/psi/formatter/JavaFormatterAlignmentTest.java b/java/java-tests/testSrc/com/intellij/psi/formatter/JavaFormatterAlignmentTest.java
new file mode 100644 (file)
index 0000000..6c500db
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2000-2010 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.psi.formatter;
+
+import com.intellij.openapi.fileTypes.StdFileTypes;
+import com.intellij.psi.codeStyle.CodeStyleSettings;
+
+/**
+ * Is intended to hold specific java formatting tests for alignment settings (
+ * <code>Project Settings - Code Style - Alignment and Braces</code>).
+ *
+ * @author Denis Zhdanov
+ * @since Apr 27, 2010 6:42:00 PM
+ */
+public class JavaFormatterAlignmentTest extends AbstractJavaFormattingTest {
+
+  public void testChainedMethodsAlignment() throws Exception {
+    // Inspired by IDEA-30369
+    getSettings().ALIGN_MULTILINE_CHAINED_METHODS = true;
+    getSettings().METHOD_CALL_CHAIN_WRAP = CodeStyleSettings.WRAP_AS_NEEDED;
+    getSettings().getIndentOptions(StdFileTypes.JAVA).CONTINUATION_INDENT_SIZE = 8;
+    doTest();
+  }
+
+}
diff --git a/java/java-tests/testSrc/com/intellij/psi/formatter/JavaFormatterNewLineTest.java b/java/java-tests/testSrc/com/intellij/psi/formatter/JavaFormatterNewLineTest.java
new file mode 100644 (file)
index 0000000..c707af4
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2000-2010 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.psi.formatter;
+
+/**
+ * Is intended to hold specific java formatting tests for <code>'Place on New Line'</code> settings (
+ * <code>Project Settings - Code Style - Alignment and Braces - Place on New Line</code>).
+ *
+ * @author Denis Zhdanov
+ * @since Apr 28, 2010 12:12:13 PM
+ */
+public class JavaFormatterNewLineTest extends AbstractJavaFormattingTest {
+
+    public void testAutomaticElseUnwrapping() throws Exception {
+        getSettings().ELSE_ON_NEW_LINE = false;
+        getSettings().KEEP_LINE_BREAKS = true;
+
+        // Inspired by IDEA-47809
+        doMethodTest(
+                
+                "if (b) {\n" +
+                "}\n" +
+                "else {\n" +
+                "}",
+
+                "if (b) {\n" +
+                "} else {\n" +
+                "}"
+        );
+    }
+    
+    public void testAutomaticCatchUnwrapping() throws Exception {
+        getSettings().CATCH_ON_NEW_LINE = false;
+        getSettings().KEEP_LINE_BREAKS = true;
+
+        // Inspired by IDEA-47809
+        doMethodTest(
+
+                "try {\n" +
+                "}\n" +
+                "catch (Exception e) {\n" +
+                "}",
+
+                "try {\n" +
+                "} catch (Exception e) {\n" +
+                "}"
+        );
+    }
+
+    public void testAutomaticFinallyUnwrapping() throws Exception {
+        getSettings().FINALLY_ON_NEW_LINE = false;
+        getSettings().KEEP_LINE_BREAKS = true;
+
+        // Inspired by IDEA-47809
+        doMethodTest(
+
+                "try {\n" +
+                "}\n" +
+                "finally {\n" +
+                "}",
+
+                "try {\n" +
+                "} finally {\n" +
+                "}"
+        );
+    }
+    
+    public void testAutomaticCatchFinallyUnwrapping() throws Exception {
+        getSettings().CATCH_ON_NEW_LINE = false;
+        getSettings().FINALLY_ON_NEW_LINE = false;
+        getSettings().KEEP_LINE_BREAKS = true;
+
+        // Inspired by IDEA-47809
+        doMethodTest(
+
+                "try {\n" +
+                "}\n" +
+                "catch (Exception e) {\n" +
+                "}\n" +
+                "finally {\n" +
+                "}",
+
+                "try {\n" +
+                "} catch (Exception e) {\n" +
+                "} finally {\n" +
+                "}"
+        );
+    }
+}
index e92029d04377938c2cad89928595533ec1ed0989..9fa0ef1932d4d52e6fc1eeef814497b7841c03a7 100644 (file)
@@ -1,38 +1,27 @@
 package com.intellij.psi.formatter;
 
-import com.intellij.JavaTestUtil;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.command.CommandProcessor;
-import com.intellij.openapi.editor.Document;
-import com.intellij.openapi.editor.EditorFactory;
-import com.intellij.openapi.editor.ex.DocumentEx;
-import com.intellij.openapi.editor.impl.DocumentImpl;
 import com.intellij.openapi.fileTypes.StdFileTypes;
 import com.intellij.openapi.roots.LanguageLevelProjectExtension;
 import com.intellij.openapi.util.TextRange;
-import com.intellij.openapi.util.io.FileUtil;
-import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.pom.java.LanguageLevel;
-import com.intellij.psi.*;
+import com.intellij.psi.JavaPsiFacade;
+import com.intellij.psi.PsiCodeFragment;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiElementFactory;
 import com.intellij.psi.codeStyle.CodeStyleManager;
 import com.intellij.psi.codeStyle.CodeStyleSettings;
 import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
-import com.intellij.testFramework.LightIdeaTestCase;
 import com.intellij.util.IncorrectOperationException;
 
-import java.io.File;
-
 
+/**
+ * <b>Note:</b> this class is too huge and hard to use. It's tests are intended to be split in multiple more fine-grained
+ * java formatting test classes.
+ */
 @SuppressWarnings({"Deprecation"})
-public class JavaFormatterTest extends LightIdeaTestCase {
-  private TextRange myTextRange;
-  private TextRange myLineRange;
-  private static final String BASE_PATH = JavaTestUtil.getJavaTestDataPath() + "/psi/formatter/java";
-
-  public void testSCR915() throws Exception {
-    getSettings().SPACE_AROUND_ADDITIVE_OPERATORS = false;
-    doTest("SCR915.java", "SCR915_after.java");
-  }
+public class JavaFormatterTest extends AbstractJavaFormattingTest {
 
   public void testForEach() throws Exception {
     doTest("ForEach.java", "ForEach_after.java");
@@ -199,42 +188,6 @@ public class JavaFormatterTest extends LightIdeaTestCase {
     doTest();
   }
 
-  public void testChainedMethodsAlignment() throws Exception {
-    getSettings().ALIGN_MULTILINE_CHAINED_METHODS = true;
-    getSettings().METHOD_CALL_CHAIN_WRAP = CodeStyleSettings.WRAP_AS_NEEDED;
-    getSettings().getIndentOptions(StdFileTypes.JAVA).CONTINUATION_INDENT_SIZE = 8;
-    doTest();
-  }
-
-  public void testNestedMethodsIndentation() throws Exception {
-    // Inspired by IDEA-43962
-
-    getSettings().getIndentOptions(StdFileTypes.JAVA).CONTINUATION_INDENT_SIZE = 4;
-
-    doMethodTest(
-      "BigDecimal.ONE\n" +
-      "      .add(BigDecimal.ONE\n" +
-      "        .add(BigDecimal.ONE\n" +
-      "        .add(BigDecimal.ONE\n" +
-      "        .add(BigDecimal.ONE\n" +
-      ".add(BigDecimal.ONE\n" +
-      " .add(BigDecimal.ONE\n" +
-      "  .add(BigDecimal.ONE\n" +
-      " .add(BigDecimal.ONE\n" +
-      "        .add(BigDecimal.ONE)))))))));",
-      "BigDecimal.ONE\n" +
-      "    .add(BigDecimal.ONE\n" +
-      "        .add(BigDecimal.ONE\n" +
-      "            .add(BigDecimal.ONE\n" +
-      "                .add(BigDecimal.ONE\n" +
-      "                    .add(BigDecimal.ONE\n" +
-      "                        .add(BigDecimal.ONE\n" +
-      "                            .add(BigDecimal.ONE\n" +
-      "                                .add(BigDecimal.ONE\n" +
-      "                                    .add(BigDecimal.ONE)))))))));"
-    );
-  }
-
   public void testSwitch() throws Exception {
     doTest();
   }
@@ -267,35 +220,6 @@ public class JavaFormatterTest extends LightIdeaTestCase {
     doTest();
   }
 
-  public void testSCR260() throws Exception {
-    final CodeStyleSettings settings = getSettings();
-    settings.IF_BRACE_FORCE = CodeStyleSettings.FORCE_BRACES_ALWAYS;
-    settings.BRACE_STYLE = CodeStyleSettings.END_OF_LINE;
-    settings.KEEP_LINE_BREAKS = false;
-    doTest();
-  }
-
-  public void testSCR114() throws Exception {
-    final CodeStyleSettings settings = getSettings();
-    settings.BRACE_STYLE = CodeStyleSettings.NEXT_LINE;
-    settings.CATCH_ON_NEW_LINE = true;
-    doTest();
-  }
-
-  public void testSCR259() throws Exception {
-    myTextRange = new TextRange(36, 60);
-    final CodeStyleSettings settings = getSettings();
-    settings.IF_BRACE_FORCE = CodeStyleSettings.FORCE_BRACES_ALWAYS;
-    settings.KEEP_LINE_BREAKS = false;
-    doTest();
-  }
-
-  public void testSCR279() throws Exception {
-    final CodeStyleSettings settings = getSettings();
-    settings.ALIGN_MULTILINE_BINARY_OPERATION = true;
-    doTest();
-  }
-
   public void testBinaryOperation() throws IncorrectOperationException {
     final CodeStyleSettings settings = getSettings();
 
@@ -412,13 +336,6 @@ public class JavaFormatterTest extends LightIdeaTestCase {
     doTest();
   }
 
-  public void testSCR395() throws Exception {
-    final CodeStyleSettings settings = getSettings();
-    settings.METHOD_BRACE_STYLE = CodeStyleSettings.END_OF_LINE;
-    doTest();
-  }
-
-
   public void testBraces() throws Exception {
     final CodeStyleSettings settings = getSettings();
 
@@ -495,21 +412,6 @@ public class JavaFormatterTest extends LightIdeaTestCase {
 
   }
 
-  public void testSCR429() throws Exception {
-    final CodeStyleSettings settings = getSettings();
-    settings.KEEP_BLANK_LINES_IN_CODE = 2;
-    settings.KEEP_BLANK_LINES_BEFORE_RBRACE = 2;
-    settings.KEEP_BLANK_LINES_IN_DECLARATIONS = 2;
-    doTest();
-  }
-
-  public void testSCR548() throws Exception {
-    final CodeStyleSettings settings = getSettings();
-    settings.getIndentOptions(StdFileTypes.JAVA).INDENT_SIZE = 4;
-    settings.getIndentOptions(StdFileTypes.JAVA).CONTINUATION_INDENT_SIZE = 2;
-    doTest();
-  }
-
   public void testExtendsList() throws Exception {
     final CodeStyleSettings settings = getSettings();
     settings.ALIGN_MULTILINE_EXTENDS_LIST = true;
@@ -707,26 +609,6 @@ public class JavaFormatterTest extends LightIdeaTestCase {
          "}");
   }
 
-  public void testSCR11799() throws Exception {
-    final CodeStyleSettings settings = getSettings();
-    settings.getIndentOptions(StdFileTypes.JAVA).CONTINUATION_INDENT_SIZE = 4;
-    settings.CLASS_BRACE_STYLE = CodeStyleSettings.NEXT_LINE;
-    settings.METHOD_BRACE_STYLE = CodeStyleSettings.NEXT_LINE;
-    doTest();
-  }
-
-  public void testSCR501() throws Exception {
-    final CodeStyleSettings settings = getSettings();
-    settings.KEEP_FIRST_COLUMN_COMMENT = true;
-    doTest();
-  }
-
-  public void testSCR879() throws Exception {
-    final CodeStyleSettings settings = getSettings();
-    settings.BRACE_STYLE = CodeStyleSettings.NEXT_LINE;
-    doTest();
-  }
-
   public void testDoNotIndentCaseFromSwitch() throws Exception {
     final CodeStyleSettings settings = getSettings();
     settings.INDENT_CASE_FROM_SWITCH = false;
@@ -740,36 +622,6 @@ public class JavaFormatterTest extends LightIdeaTestCase {
                                                                                                                     "}");
   }
 
-  public void testSCR547() throws Exception {
-    doTextTest("class Foo { \n" +
-               "    Object[] objs = { \n" +
-               "            new Object() { \n" +
-               "        public String toString() { \n" +
-               "            return \"x\"; \n" +
-               "        } \n" +
-               "    } \n" +
-               "    }; \n" +
-"}", "class Foo {\n" +
-     "    Object[] objs = {\n" +
-     "            new Object() {\n" +
-     "                public String toString() {\n" +
-     "                    return \"x\";\n" +
-     "                }\n" +
-     "            }\n" +
-     "    };\n" +
-     "}");
-  }
-
-  public void testSCR11296() throws Exception {
-    final CodeStyleSettings settings = getSettings();
-    settings.RIGHT_MARGIN = 50;
-    settings.WRAP_COMMENTS = true;
-    settings.ENABLE_JAVADOC_FORMATTING = true;
-    settings.JD_P_AT_EMPTY_LINES = false;
-    settings.JD_KEEP_EMPTY_LINES = false;
-    doTest();
-  }
-
   public void testClass2() throws Exception {
     final CodeStyleSettings settings = getSettings();
     settings.KEEP_FIRST_COLUMN_COMMENT = false;
@@ -800,52 +652,6 @@ public class JavaFormatterTest extends LightIdeaTestCase {
                "class Foo {\n" + "    void foo() {\n" + "        return name != null ?1 :2;\n" + "    }\n" + "}");
   }
 
-  public void testSCR479() throws Exception {
-    final CodeStyleSettings settings = getSettings();
-    settings.RIGHT_MARGIN = 80;
-    settings.TERNARY_OPERATION_WRAP = CodeStyleSettings.WRAP_AS_NEEDED;
-    doTextTest("public class Foo {\n" +
-               "    public static void main(String[] args) {\n" +
-               "        if (name != null ?                !name.equals(that.name) : that.name !=                null)\n" +
-               "            return false;\n" +
-               "    }\n" +
-"}", "public class Foo {\n" +
-     "    public static void main(String[] args) {\n" +
-     "        if (name != null ? !name.equals(that.name) : that.name != null)\n" +
-     "            return false;\n" +
-     "    }\n" +
-     "}");
-  }
-
-  public void testSCR190() throws Exception {
-    final CodeStyleSettings settings = getSettings();
-    settings.KEEP_LINE_BREAKS = false;
-    doTextTest("public class EntityObject \n" +
-               "{ \n" +
-               "    private Integer id; \n" +
-               "\n" +
-               "    public Integer getId() \n" +
-               "    { \n" +
-               "        return id; \n" +
-               "    } \n" +
-               "\n" +
-               "    public void setId(Integer id) \n" +
-               "    { \n" +
-               "        this.id = id; \n" +
-               "    } \n" +
-"}", "public class EntityObject {\n" +
-     "    private Integer id;\n" +
-     "\n" +
-     "    public Integer getId() {\n" +
-     "        return id;\n" +
-     "    }\n" +
-     "\n" +
-     "    public void setId(Integer id) {\n" +
-     "        this.id = id;\n" +
-     "    }\n" +
-     "}");
-  }
-
   public void testMethodCallChain() throws Exception {
     doTextTest("class Foo{\n" +
                "    void foo(){\n" +
@@ -908,29 +714,6 @@ public class JavaFormatterTest extends LightIdeaTestCase {
      "}");
   }
 
-  public void testSCR1535() throws Exception {
-    final CodeStyleSettings settings = getSettings();
-    settings.BRACE_STYLE = CodeStyleSettings.NEXT_LINE;
-    settings.CLASS_BRACE_STYLE = CodeStyleSettings.NEXT_LINE;
-    settings.METHOD_BRACE_STYLE = CodeStyleSettings.NEXT_LINE;
-    doTextTest("public class Foo {\n" +
-               "    public int foo() {\n" +
-               "        if (a) {\n" +
-               "            return;\n" +
-               "        }\n" +
-               "    }\n" +
-"}", "public class Foo\n" +
-     "{\n" +
-     "    public int foo()\n" +
-     "    {\n" +
-     "        if (a)\n" +
-     "        {\n" +
-     "            return;\n" +
-     "        }\n" +
-     "    }\n" +
-     "}");
-  }
-
   public void testComment1() throws Exception {
     doTextTest("class Foo {\n" +
                "    public boolean mErrorFlage;\n" +
@@ -1037,14 +820,6 @@ public class JavaFormatterTest extends LightIdeaTestCase {
     doTest("SpacesBeforeLBrace.java", "SpacesBeforeLBrace.java");
   }
 
-  public void testSCR970() throws Exception {
-    final CodeStyleSettings settings = getSettings();
-    settings.THROWS_KEYWORD_WRAP = CodeStyleSettings.WRAP_ALWAYS;
-    settings.THROWS_LIST_WRAP = CodeStyleSettings.WRAP_AS_NEEDED;
-    settings.METHOD_PARAMETERS_WRAP = CodeStyleSettings.WRAP_AS_NEEDED;
-    doTest();
-  }
-
   public void testCommentBeforeField() throws Exception {
     final CodeStyleSettings settings = getSettings();
     settings.KEEP_LINE_BREAKS = false;
@@ -1088,10 +863,6 @@ public class JavaFormatterTest extends LightIdeaTestCase {
 
   }
 
-  private static CodeStyleSettings getSettings() {
-    return CodeStyleSettingsManager.getSettings(getProject());
-  }
-
   public void testElseOnNewLine() throws Exception {
     doTextTest("class Foo{\n" + "void foo() {\n" + "if (a)\n" + "return;\n" + "else\n" + "return;\n" + "}\n" + "}", "class Foo {\n" +
                                                                                                                     "    void foo() {\n" +
@@ -1134,47 +905,6 @@ public class JavaFormatterTest extends LightIdeaTestCase {
      "}");
   }
 
-  public void testSCR1047() throws Exception {
-    doTextTest("class Foo{\n" + "    void foo(){\n" + "        String field1, field2;\n" + "    }\n" + "}",
-               "class Foo {\n" + "    void foo() {\n" + "        String field1, field2;\n" + "    }\n" + "}");
-  }
-
-  public void testSCR524() throws Exception {
-    getSettings().METHOD_BRACE_STYLE = CodeStyleSettings.NEXT_LINE_SHIFTED;
-    getSettings().KEEP_SIMPLE_METHODS_IN_ONE_LINE = true;
-    getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = false;
-    doTextTest("class Foo {\n" + "    void foo() { return;}" + "}", "class Foo {\n" + "    void foo() { return;}\n" + "}");
-
-    getSettings().BRACE_STYLE = CodeStyleSettings.NEXT_LINE_SHIFTED2;
-    getSettings().KEEP_SIMPLE_METHODS_IN_ONE_LINE = false;
-    getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true;
-    getSettings().METHOD_BRACE_STYLE = CodeStyleSettings.END_OF_LINE;
-
-    doTextTest("class Foo{\n" +
-               "void foo() {\n" +
-               "if(a) {return;}\n" +
-               "for(a = 0; a < 10; a++) {return;}\n" +
-               "switch(a) {case 1: return;}\n" +
-               "do{return;} while (a);\n" +
-               "while(a){return;}\n" +
-               "try{return;} catch(Ex e){return;} finally{return;}\n" +
-               "}\n" +
-"}", "class Foo {\n" +
-     "    void foo() {\n" +
-     "        if (a) {return;}\n" +
-     "        for (a = 0; a < 10; a++) {return;}\n" +
-     "        switch (a)\n" +
-     "            {\n" +
-     "                case 1:\n" +
-     "                    return;\n" +
-     "            }\n" +
-     "        do {return;} while (a);\n" +
-     "        while (a) {return;}\n" +
-     "        try {return;} catch (Ex e) {return;} finally {return;}\n" +
-     "    }\n" +
-     "}");
-  }
-
   public void testFirstArgumentWrapping() throws Exception {
     getSettings().RIGHT_MARGIN = 20;
     getSettings().CALL_PARAMETERS_WRAP = CodeStyleSettings.WRAP_AS_NEEDED;
@@ -1334,31 +1064,6 @@ public class JavaFormatterTest extends LightIdeaTestCase {
                "class Foo {\n" + "    void foo() {\n" + "\n" + "    }\n" + "}");
   }
 
-  public void testSCR2632() throws Exception {
-    getSettings().ENABLE_JAVADOC_FORMATTING = true;
-    getSettings().WRAP_COMMENTS = true;
-    getSettings().RIGHT_MARGIN = 20;
-
-    doTextTest("/**\n" + " * <p />\n" + " * Another paragraph of the description placed after blank line.\n" + " */\n" + "class A{}",
-               "/**\n" +
-               " * <p/>\n" +
-               " * Another paragraph\n" +
-               " * of the description\n" +
-               " * placed after\n" +
-               " * blank line.\n" +
-               " */\n" +
-               "class A {\n" +
-               "}");
-  }
-
-  public void testSCR1486() throws Exception {
-    doTextTest("public class Test {\n" + "  private BigDecimal\n" + "}", "public class Test {\n" + "    private BigDecimal\n" + "}");
-
-    doTextTest("public class Test {\n" + "  @NotNull private BigDecimal\n" + "}",
-               "public class Test {\n" + "    @NotNull\n" + "    private BigDecimal\n" + "}");
-
-  }
-
   public void testJavaDocLeadingAsterisksAreDisabled() throws Exception {
     getSettings().JD_LEADING_ASTERISKS_ARE_ENABLED = false;
     doTextTest("class Foo {\n" +
@@ -1438,35 +1143,6 @@ public class JavaFormatterTest extends LightIdeaTestCase {
     assertEquals("a = 1;\n" + "int b = 2;", result[0].getText());
   }
 
-  public void test1607() throws Exception {
-    getSettings().RIGHT_MARGIN = 30;
-    getSettings().METHOD_BRACE_STYLE = CodeStyleSettings.NEXT_LINE;
-    getSettings().KEEP_SIMPLE_METHODS_IN_ONE_LINE = true;
-    getSettings().ALIGN_MULTILINE_PARAMETERS = true;
-    getSettings().METHOD_PARAMETERS_WRAP = CodeStyleSettings.WRAP_AS_NEEDED;
-    doTextTest("class TEst {\n" + "void foo(A a,B b){ /* compiled code */ }\n" + "}",
-               "class TEst {\n" + "    void foo(A a, B b)\n" + "    { /* compiled code */ }\n" + "}");
-  }
-
-  public void testSCR1615() throws Exception {
-    getSettings().CLASS_BRACE_STYLE = CodeStyleSettings.NEXT_LINE_SHIFTED;
-    getSettings().METHOD_BRACE_STYLE = CodeStyleSettings.NEXT_LINE_SHIFTED;
-    getSettings().BRACE_STYLE = CodeStyleSettings.NEXT_LINE_SHIFTED;
-
-    doTextTest(
-      "public class ZZZZ \n" + "   { \n" + "   public ZZZZ() \n" + "      { \n" + "      if (a){\n" + "foo();}\n" + "      } \n" + "   }",
-      "public class ZZZZ\n" +
-      "    {\n" +
-      "    public ZZZZ()\n" +
-      "        {\n" +
-      "        if (a)\n" +
-      "            {\n" +
-      "            foo();\n" +
-      "            }\n" +
-      "        }\n" +
-      "    }");
-  }
-
   public void testNewLineAfterJavaDocs() throws Exception {
     doTextTest("/** @noinspection InstanceVariableNamingConvention*/class Foo{\n" +
                "/** @noinspection InstanceVariableNamingConvention*/int myFoo;\n" +
@@ -1529,90 +1205,6 @@ public class JavaFormatterTest extends LightIdeaTestCase {
 
   }
 
-  public void testSCR3062() throws Exception {
-    getSettings().KEEP_LINE_BREAKS = false;
-    getSettings().METHOD_CALL_CHAIN_WRAP = CodeStyleSettings.WRAP_AS_NEEDED;
-    getSettings().CALL_PARAMETERS_WRAP = CodeStyleSettings.WRAP_AS_NEEDED;
-    getSettings().ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
-    getSettings().RIGHT_MARGIN = 80;
-
-    getSettings().PREFER_PARAMETERS_WRAP = true;
-
-    doTextTest("public class Foo { \n" +
-               "    public static void main() { \n" +
-               "        foo.foobelize().foobelize().foobelize().bar(\"The quick brown\", \n" +
-               "                                                    \"fox jumped over\", \n" +
-               "                                                    \"the lazy\", \"dog\"); \n" +
-               "    } \n" +
-"}", "public class Foo {\n" +
-     "    public static void main() {\n" +
-     "        foo.foobelize().foobelize().foobelize().bar(\"The quick brown\",\n" +
-     "                                                    \"fox jumped over\",\n" +
-     "                                                    \"the lazy\", \"dog\");\n" +
-     "    }\n" +
-     "}");
-
-    getSettings().PREFER_PARAMETERS_WRAP = false;
-
-    doTextTest("public class Foo { \n" +
-               "    public static void main() { \n" +
-               "        foo.foobelize().foobelize().foobelize().bar(\"The quick brown\", \n" +
-               "                                                    \"fox jumped over\", \n" +
-               "                                                    \"the lazy\", \"dog\"); \n" +
-               "    } \n" +
-"}", "public class Foo {\n" +
-     "    public static void main() {\n" +
-     "        foo.foobelize().foobelize().foobelize()\n" +
-     "                .bar(\"The quick brown\", \"fox jumped over\", \"the lazy\", \"dog\");\n" +
-     "    }\n" +
-     "}");
-
-  }
-
-  public void testSCR1658() throws Exception {
-    doTextTest("/** \n" + " * @author\tMike\n" + " */\n" + "public class Foo {\n" + "}",
-               "/**\n" + " * @author Mike\n" + " */\n" + "public class Foo {\n" + "}");
-  }
-
-  public void testSCR1699() throws Exception {
-    doTextTest("class Test {\n" + "    Test(String t1 , String t2) {\n" + "    }\n" + "}",
-               "class Test {\n" + "    Test(String t1, String t2) {\n" + "    }\n" + "}");
-  }
-
-  public void testSCR1700() throws Exception {
-    doTextTest("class Test {\n" + "    Test(String      t1 , String      t2) {\n" + "    }\n" + "}",
-               "class Test {\n" + "    Test(String t1, String t2) {\n" + "    }\n" + "}");
-  }
-
-  public void testSCR1701() throws Exception {
-    getSettings().SPACE_WITHIN_METHOD_CALL_PARENTHESES = true;
-    getSettings().SPACE_WITHIN_METHOD_PARENTHESES = false;
-    getSettings().CALL_PARAMETERS_WRAP = CodeStyleSettings.DO_NOT_WRAP;
-    getSettings().CALL_PARAMETERS_LPAREN_ON_NEXT_LINE = true;
-    getSettings().CALL_PARAMETERS_RPAREN_ON_NEXT_LINE = true;
-    doTextTest("class Foo {\n" + "    void foo() {\n" + "        foo(a,b);" + "    }\n" + "}",
-               "class Foo {\n" + "    void foo() {\n" + "        foo( a, b );\n" + "    }\n" + "}");
-  }
-
-  public void testSCR1703() throws Exception {
-    getSettings().BRACE_STYLE = CodeStyleSettings.NEXT_LINE;
-    doTextTest("class Foo{\n" +
-               "    void foo() {\n" +
-               "        for (Object o : localizations) {\n" +
-               "            //do something \n" +
-               "        }\n" +
-               "    }\n" +
-"}", "class Foo {\n" +
-     "    void foo() {\n" +
-     "        for (Object o : localizations)\n" +
-     "        {\n" +
-     "            //do something \n" +
-     "        }\n" +
-     "    }\n" +
-     "}");
-  }
-
-
   public void testJavaDocIndentation() throws Exception {
     getSettings().getIndentOptions(StdFileTypes.JAVA).INDENT_SIZE = 2;
     getSettings().getIndentOptions(StdFileTypes.JAVA).CONTINUATION_INDENT_SIZE = 2;
@@ -1645,44 +1237,6 @@ public class JavaFormatterTest extends LightIdeaTestCase {
      "}");
   }
 
-  public void testSCR1804() throws Exception {
-    getSettings().ALIGN_MULTILINE_ASSIGNMENT = true;
-    doTextTest(
-      "class Foo {\n" + "    void foo() {\n" + "        int i;\n" + "        i = \n" + "                1 + 2;\n" + "    }\n" + "}",
-      "class Foo {\n" + "    void foo() {\n" + "        int i;\n" + "        i =\n" + "                1 + 2;\n" + "    }\n" + "}");
-
-    doTextTest("class Foo {\n" + "    void foo() {\n" + "        i = j =\n" + "        k = l = 1 + 2;\n" + "    }\n" + "}",
-               "class Foo {\n" + "    void foo() {\n" + "        i = j =\n" + "        k = l = 1 + 2;\n" + "    }\n" + "}");
-
-  }
-
-  public void testSCR1795() throws Exception {
-    getSettings().BRACE_STYLE = CodeStyleSettings.NEXT_LINE_IF_WRAPPED;
-    doTextTest("public class Test {\n" +
-               "    public static void main(String[] args) {\n" +
-               "        do {\n" +
-               "            // ...\n" +
-               "        } while (true);\n" +
-               "    }\n" +
-"}", "public class Test {\n" +
-     "    public static void main(String[] args) {\n" +
-     "        do {\n" +
-     "            // ...\n" +
-     "        } while (true);\n" +
-     "    }\n" +
-     "}");
-  }
-
-  public void testSCR1936() throws Exception {
-    getSettings().BLANK_LINES_AFTER_CLASS_HEADER = 4;
-    doTextTest("/**\n" + " * Foo - test class\n" + " */\n" + "class Foo{\n" + "}",
-               "/**\n" + " * Foo - test class\n" + " */\n" + "class Foo {\n" + "\n" + "\n" + "\n" + "\n" + "}");
-
-    doTextTest("/**\n" + " * Foo - test class\n" + " */\n" + "class Foo{\n" + "    int myFoo;\n" + "}",
-               "/**\n" + " * Foo - test class\n" + " */\n" + "class Foo {\n" + "\n" + "\n" + "\n" + "\n" + "    int myFoo;\n" + "}");
-
-  }
-
   public void testRemoveLineBreak() throws Exception {
     getSettings().KEEP_LINE_BREAKS = true;
     getSettings().CLASS_BRACE_STYLE = CodeStyleSettings.END_OF_LINE;
@@ -1784,25 +1338,6 @@ public class JavaFormatterTest extends LightIdeaTestCase {
 
   }
 
-  public void test1980() throws Exception {
-    getSettings().RIGHT_MARGIN = 144;
-    getSettings().TERNARY_OPERATION_WRAP = CodeStyleSettings.WRAP_ON_EVERY_ITEM;
-    getSettings().METHOD_CALL_CHAIN_WRAP = CodeStyleSettings.WRAP_AS_NEEDED;
-    getSettings().ALIGN_MULTILINE_TERNARY_OPERATION = true;
-    getSettings().TERNARY_OPERATION_SIGNS_ON_NEXT_LINE = true;
-    doTextTest("class Foo{\n" +
-               "    void foo() {\n" +
-               "final VirtualFile moduleRoot = moduleRelativePath.equals(\"\") ? projectRootDirAfter : projectRootDirAfter.findFileByRelativePath(moduleRelativePath);\n" +
-               "    }\n" +
-"}", "class Foo {\n" +
-     "    void foo() {\n" +
-     "        final VirtualFile moduleRoot = moduleRelativePath.equals(\"\")\n" +
-     "                                       ? projectRootDirAfter\n" +
-     "                                       : projectRootDirAfter.findFileByRelativePath(moduleRelativePath);\n" +
-     "    }\n" +
-     "}");
-  }
-
   public void testStaticBlockBraces() throws Exception {
     getSettings().BRACE_STYLE = CodeStyleSettings.END_OF_LINE;
     doTextTest("class Foo {\n" + "    static {\n" + "        //comment\n" + "        i = foo();\n" + "    }\n" + "}",
@@ -1834,40 +1369,6 @@ public class JavaFormatterTest extends LightIdeaTestCase {
 
   }
 
-  public void testSCR2089() throws Exception {
-    doTextTest("class Test { \n" +
-               "    void test(int i) { \n" +
-               "        switch (i) { \n" +
-               "            case 1: { \n" +
-               "                int x = 0; \n" +
-               "                System.out.println(x); \n" +
-               "            } \n" +
-               "                break; \n" +
-               "            case 2: { \n" +
-               "                int y = 0; \n" +
-               "                System.out.println(y); \n" +
-               "            } \n" +
-               "                break; \n" +
-               "        } \n" +
-               "    } \n" +
-"}", "class Test {\n" +
-     "    void test(int i) {\n" +
-     "        switch (i) {\n" +
-     "            case 1: {\n" +
-     "                int x = 0;\n" +
-     "                System.out.println(x);\n" +
-     "            }\n" +
-     "            break;\n" +
-     "            case 2: {\n" +
-     "                int y = 0;\n" +
-     "                System.out.println(y);\n" +
-     "            }\n" +
-     "            break;\n" +
-     "        }\n" +
-     "    }\n" +
-     "}");
-  }
-
   public void testBraces2() throws Exception {
     getSettings().BRACE_STYLE = CodeStyleSettings.NEXT_LINE_IF_WRAPPED;
     doTextTest("class Foo {\n" +
@@ -1947,29 +1448,6 @@ public class JavaFormatterTest extends LightIdeaTestCase {
 
   }
 
-  public void testSCR2122() throws Exception {
-    getSettings().BLANK_LINES_AFTER_CLASS_HEADER = 3;
-
-    doTextTest("class Foo {\n" +
-               "    void foo() {\n" +
-               "        new Runnable() {\n" +
-               "            public void run() {\n" +
-               "            }\n" +
-               "        }\n" +
-               "    }\n" +
-"}", "class Foo {\n" +
-     "\n" +
-     "\n" +
-     "\n" +
-     "    void foo() {\n" +
-     "        new Runnable() {\n" +
-     "            public void run() {\n" +
-     "            }\n" +
-     "        }\n" +
-     "    }\n" +
-     "}");
-  }
-
   public void testSynchronized() throws Exception {
 
     getSettings().BRACE_STYLE = CodeStyleSettings.END_OF_LINE;
@@ -2014,1409 +1492,1736 @@ public class JavaFormatterTest extends LightIdeaTestCase {
 
   }
 
-  public void testSCR2132() throws Exception {
-    getSettings().BRACE_STYLE = CodeStyleSettings.NEXT_LINE_IF_WRAPPED;
-    getSettings().ELSE_ON_NEW_LINE = true;
+  public void testNextLineShiftedForBlockStatement() throws Exception {
+    getSettings().BRACE_STYLE = CodeStyleSettings.NEXT_LINE_SHIFTED;
+
+    doTextTest("class Foo {\n" + "    void foo() {\n" + "        if (a)\n" + "        foo();\n" + "    }\n" + "}",
+               "class Foo {\n" + "    void foo() {\n" + "        if (a)\n" + "            foo();\n" + "    }\n" + "}");
+  }
+
+  public void testFieldWithJavadocAndAnnotation() throws Exception {
+    doTextTest("class Foo {\n" + "    /**\n" + "     * java doc\n" + "     */\n" + "    @NoInspection\n" + "    String field;\n" + "}",
+               "class Foo {\n" + "    /**\n" + "     * java doc\n" + "     */\n" + "    @NoInspection\n" + "    String field;\n" + "}");
+  }
 
+  public void testLongCallChainAfterElse() throws Exception {
+    getSettings().BRACE_STYLE = CodeStyleSettings.NEXT_LINE;
+    getSettings().KEEP_CONTROL_STATEMENT_IN_ONE_LINE = true;
+    getSettings().KEEP_SIMPLE_METHODS_IN_ONE_LINE = true;
+    getSettings().ELSE_ON_NEW_LINE = false;
+    getSettings().RIGHT_MARGIN = 110;
+    getSettings().KEEP_LINE_BREAKS = false;
     doTextTest("class Foo {\n" +
                "    void foo() {\n" +
-               "        if (!rightPanel.isAncestorOf(validationPanel)) \n" +
-               "                {\n" +
-               "                    splitPane.setDividerLocation(1.0);\n" +
-               "                }\n" +
-               "                else\n" +
-               "                {\n" +
-               "                    splitPane.setDividerLocation(0.7);\n" +
-               "                }" +
+               "        if (types.length > 1) // returns multiple columns\n" +
+               "        {\n" +
+               "        } else\n" +
+               "            result.add(initializeObject(os, types[0], initializeCollections, initializeAssociations, initializeChildren));" +
                "    }\n" +
 "}", "class Foo {\n" +
      "    void foo() {\n" +
-     "        if (!rightPanel.isAncestorOf(validationPanel)) {\n" +
-     "            splitPane.setDividerLocation(1.0);\n" +
-     "        }\n" +
-     "        else {\n" +
-     "            splitPane.setDividerLocation(0.7);\n" +
-     "        }\n" +
+     "        if (types.length > 1) // returns multiple columns\n" +
+     "        {\n" +
+     "        } else\n" +
+     "            result.add(initializeObject(os, types[0], initializeCollections, initializeAssociations, initializeChildren));\n" +
      "    }\n" +
      "}");
   }
 
-  public void testNextLineShiftedForBlockStatement() throws Exception {
-    getSettings().BRACE_STYLE = CodeStyleSettings.NEXT_LINE_SHIFTED;
-
-    doTextTest("class Foo {\n" + "    void foo() {\n" + "        if (a)\n" + "        foo();\n" + "    }\n" + "}",
-               "class Foo {\n" + "    void foo() {\n" + "        if (a)\n" + "            foo();\n" + "    }\n" + "}");
-  }
+  public void testSpacesIncode() throws Exception {
 
-  private void doTest() throws Exception {
-    doTest(getTestName(false) + ".java", getTestName(false) + "_after.java");
-  }
+    final JavaPsiFacade facade = getJavaFacade();
+    final LanguageLevel level = LanguageLevelProjectExtension.getInstance(facade.getProject()).getLanguageLevel();
 
-  private void doTest(String fileNameBefore, String fileNameAfter) throws Exception {
+    LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
 
-    doTextTest(loadFile(fileNameBefore), loadFile(fileNameAfter));
+    try {
+      doTextTest("class C<Y, X> {\n" + "}", "class C<Y, X> {\n" + "}");
 
+      getSettings().SPACE_BEFORE_METHOD_LBRACE = true;
+      getSettings().KEEP_SIMPLE_METHODS_IN_ONE_LINE = true;
 
-  }
+      doTextTest("enum En {\n" + "    A(10) {},\n" + "    B(10) {},\n" + "    C(10);\n" + "\n" + "    En(int i) { }\n" + "}",
+                 "enum En {\n" + "    A(10) {},\n" + "    B(10) {},\n" + "    C(10);\n" + "\n" + "    En(int i) { }\n" + "}");
 
-  private void doTextTest(final String text, String textAfter) throws IncorrectOperationException {
-    final PsiFile file = createPseudoPhysicalFile("A.java", text);
+      doTextTest("class C {\n" +
+                 "    void foo (Map<?, String> s) {\n" +
+                 "        Set<? extends Map<?, String>.Entry<?, String>> temp = s.entries();\n" +
+                 "    }\n" +
+"}", "class C {\n" +
+     "    void foo(Map<?, String> s) {\n" +
+     "        Set<? extends Map<?, String>.Entry<?, String>> temp = s.entries();\n" +
+     "    }\n" +
+     "}");
 
-    if (myLineRange != null) {
-      final DocumentImpl document = new DocumentImpl(text);
-      myTextRange =
-        new TextRange(document.getLineStartOffset(myLineRange.getStartOffset()), document.getLineEndOffset(myLineRange.getEndOffset()));
+      doTextTest("class B {\n" +
+                 "    public final A<String> myDelegate = new A<String>();\n" +
+                 "\n" +
+                 "    public List<? extends String> method1() {\n" +
+                 "        return myDelegate.method1();\n" +
+                 "    }\n" +
+                 "\n" +
+                 "    public String method2(String t) {\n" +
+                 "        return myDelegate.method2(t);\n" +
+                 "    }\n" +
+"}", "class B {\n" +
+     "    public final A<String> myDelegate = new A<String>();\n" +
+     "\n" +
+     "    public List<? extends String> method1() {\n" +
+     "        return myDelegate.method1();\n" +
+     "    }\n" +
+     "\n" +
+     "    public String method2(String t) {\n" +
+     "        return myDelegate.method2(t);\n" +
+     "    }\n" +
+     "}");
+    }
+    finally {
+      LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(level);
     }
 
-    /*
-    CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
-      public void run() {
-        ApplicationManager.getApplication().runWriteAction(new Runnable() {
-          public void run() {
-            performFormatting(file);
-          }
-        });
-      }
-    }, null, null);
-
-    assertEquals(prepareText(textAfter), prepareText(file.getText()));
-
-      
-    */
-
-    final PsiDocumentManager manager = PsiDocumentManager.getInstance(getProject());
-    final Document document = manager.getDocument(file);
+  }
 
+  ///IDEA-7761
+  public void testKeepBlankLineInCodeBeforeComment() throws Exception {
+    getSettings().KEEP_BLANK_LINES_IN_CODE = 1;
+    getSettings().KEEP_BLANK_LINES_IN_DECLARATIONS = 0;
+    getSettings().KEEP_FIRST_COLUMN_COMMENT = false;
 
-    CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
-      public void run() {
-        ApplicationManager.getApplication().runWriteAction(new Runnable() {
-          public void run() {
-            document.replaceString(0, document.getTextLength(), text);
-            manager.commitDocument(document);
-            try {
-              if (myTextRange != null) {
-                CodeStyleManager.getInstance(getProject()).reformatText(file, myTextRange.getStartOffset(), myTextRange.getEndOffset());
-              }
-              else {
-                CodeStyleManager.getInstance(getProject())
-                  .reformatText(file, file.getTextRange().getStartOffset(), file.getTextRange().getEndOffset());
-              }
-            }
-            catch (IncorrectOperationException e) {
-              assertTrue(e.getLocalizedMessage(), false);
-            }
-          }
-        });
-      }
-    }, "", "");
+    doTextTest("public class ReformatProblem {\n" +
+               "\n" +
+               "    //comment in declaration\n" +
+               "    public static void main(String[] args) {\n" +
+               "        for (String arg : args) {\n" +
+               "            \n" +
+               "            // a first system out\n" +
+               "            System.out.println(\"\");\n" +
+               "            \n" +
+               "            // another system out\n" +
+               "            System.out.println(\"arg = \" + arg);\n" +
+               "        }\n" +
+               "    }\n" +
+"}", "public class ReformatProblem {\n" +
+     "    //comment in declaration\n" +
+     "    public static void main(String[] args) {\n" +
+     "        for (String arg : args) {\n" +
+     "\n" +
+     "            // a first system out\n" +
+     "            System.out.println(\"\");\n" +
+     "\n" +
+     "            // another system out\n" +
+     "            System.out.println(\"arg = \" + arg);\n" +
+     "        }\n" +
+     "    }\n" +
+     "}");
 
+    getSettings().KEEP_BLANK_LINES_IN_CODE = 0;
+    getSettings().KEEP_BLANK_LINES_IN_DECLARATIONS = 1;
+    getSettings().KEEP_FIRST_COLUMN_COMMENT = false;
 
-    if (document == null) {
-      fail("Don't expect the document to be null");
-      return;
-    }
-    assertEquals(prepareText(textAfter), prepareText(document.getText()));
-    manager.commitDocument(document);
-    assertEquals(prepareText(textAfter), prepareText(file.getText()));
+    doTextTest("public class ReformatProblem {\n" +
+               "\n" +
+               "    //comment in declaration\n" +
+               "    public static void main(String[] args) {\n" +
+               "        for (String arg : args) {\n" +
+               "            \n" +
+               "            // a first system out\n" +
+               "            System.out.println(\"\");\n" +
+               "            \n" +
+               "            // another system out\n" +
+               "            System.out.println(\"arg = \" + arg);\n" +
+               "        }\n" +
+               "    }\n" +
+"}", "public class ReformatProblem {\n" +
+     "\n" +
+     "    //comment in declaration\n" +
+     "    public static void main(String[] args) {\n" +
+     "        for (String arg : args) {\n" +
+     "            // a first system out\n" +
+     "            System.out.println(\"\");\n" +
+     "            // another system out\n" +
+     "            System.out.println(\"arg = \" + arg);\n" +
+     "        }\n" +
+     "    }\n" +
+     "}");
 
   }
 
-  public void testIDEADEV1047() throws Exception {
-    doTextTest("class Foo{\n" + "String field1\n" + ",\n" + "field2\n" + ";" + "}",
-               "class Foo {\n" + "    String field1,\n" + "            field2;\n" + "}");
-
-    doTextTest("class Foo{\n" + "void foo() {\n" + "    String var1\n" + ",\n" + "var2\n" + ";\n" + "    }\n" + "}",
-               "class Foo {\n" + "    void foo() {\n" + "        String var1,\n" + "                var2;\n" + "    }\n" + "}");
+  public void testSpaceBeforeTryBrace() throws Exception {
+    getSettings().SPACE_BEFORE_TRY_LBRACE = false;
+    getSettings().SPACE_BEFORE_FINALLY_LBRACE = true;
+    doTextTest("class Foo{\n" + "    void foo() {\n" + "        try {\n" + "        } finally {\n" + "        }\n" + "    }\n" + "}",
+               "class Foo {\n" + "    void foo() {\n" + "        try{\n" + "        } finally {\n" + "        }\n" + "    }\n" + "}");
 
-  }
+    getSettings().SPACE_BEFORE_TRY_LBRACE = true;
+    getSettings().SPACE_BEFORE_FINALLY_LBRACE = false;
 
-  public void testIDEADEV1047_2() throws Exception {
-    doTextTest("class Foo{\n" + "String field1\n" + ",\n" + "field2\n" + "; String field3;" + "}",
-               "class Foo {\n" + "    String field1,\n" + "            field2;\n" + "    String field3;\n" + "}");
+    doTextTest("class Foo{\n" + "    void foo() {\n" + "        try {\n" + "        } finally {\n" + "        }\n" + "    }\n" + "}",
+               "class Foo {\n" + "    void foo() {\n" + "        try {\n" + "        } finally{\n" + "        }\n" + "    }\n" + "}");
 
   }
 
-  public void testFieldWithJavadocAndAnnotation() throws Exception {
-    doTextTest("class Foo {\n" + "    /**\n" + "     * java doc\n" + "     */\n" + "    @NoInspection\n" + "    String field;\n" + "}",
-               "class Foo {\n" + "    /**\n" + "     * java doc\n" + "     */\n" + "    @NoInspection\n" + "    String field;\n" + "}");
+  public void testFormatComments() throws Exception {
+    getSettings().ENABLE_JAVADOC_FORMATTING = true;
+    doTextTest("public class Test {\n" + "\n" + "    /**\n" + "     * The s property.\n" + "     */\n" + "    private String s;\n" + "}",
+               "public class Test {\n" + "\n" + "    /**\n" + "     * The s property.\n" + "     */\n" + "    private String s;\n" + "}");
+
   }
 
-  public void testSCR2241() throws Exception {
-    getSettings().BRACE_STYLE = CodeStyleSettings.NEXT_LINE_SHIFTED;
-    getSettings().SPECIAL_ELSE_IF_TREATMENT = true;
-    getSettings().ELSE_ON_NEW_LINE = true;
-    doTextTest("class Foo {\n" +
-               "    void foo() {\n" +
-               "        if (a)\n" +
-               "        {\n" +
-               "        }\n" +
-               "        else\n" +
-               "        {\n" +
+  public void testDoNotWrapLBrace() throws IncorrectOperationException {
+    getSettings().BRACE_STYLE = CodeStyleSettings.END_OF_LINE;
+    getSettings().RIGHT_MARGIN = 66;
+    doTextTest("public class Test {\n" +
+               "    void foo(){\n" +
+               "        if (veryLongIdentifier1 == 1 && veryLongIdentifier2 == 2) {\n" +
+               "            doSmth();\n" +
                "        }\n" +
                "    }\n" +
-"}", "class Foo {\n" +
+"}", "public class Test {\n" +
      "    void foo() {\n" +
-     "        if (a)\n" +
-     "            {\n" +
-     "            }\n" +
-     "        else\n" +
-     "            {\n" +
-     "            }\n" +
+     "        if (veryLongIdentifier1 == 1 && veryLongIdentifier2 == 2) {\n" +
+     "            doSmth();\n" +
+     "        }\n" +
      "    }\n" +
      "}");
   }
 
-  public void testLongCallChainAfterElse() throws Exception {
-    getSettings().BRACE_STYLE = CodeStyleSettings.NEXT_LINE;
-    getSettings().KEEP_CONTROL_STATEMENT_IN_ONE_LINE = true;
-    getSettings().KEEP_SIMPLE_METHODS_IN_ONE_LINE = true;
-    getSettings().ELSE_ON_NEW_LINE = false;
-    getSettings().RIGHT_MARGIN = 110;
-    getSettings().KEEP_LINE_BREAKS = false;
-    doTextTest("class Foo {\n" +
-               "    void foo() {\n" +
-               "        if (types.length > 1) // returns multiple columns\n" +
-               "        {\n" +
-               "        } else\n" +
-               "            result.add(initializeObject(os, types[0], initializeCollections, initializeAssociations, initializeChildren));" +
-               "    }\n" +
-"}", "class Foo {\n" +
-     "    void foo() {\n" +
-     "        if (types.length > 1) // returns multiple columns\n" +
-     "        {\n" +
-     "        } else\n" +
-     "            result.add(initializeObject(os, types[0], initializeCollections, initializeAssociations, initializeChildren));\n" +
-     "    }\n" +
-     "}");
+  public void testNewLinesAroundArrayInitializer() throws IncorrectOperationException {
+    getSettings().ARRAY_INITIALIZER_WRAP = CodeStyleSettings.WRAP_AS_NEEDED;
+    getSettings().ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE = true;
+    getSettings().ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE = true;
+    getSettings().RIGHT_MARGIN = 40;
+    doTextTest("class Foo {\n" + "    int[] a = new int[]{1,2,0x0052,0x0053,0x0054,0x0054,0x0054};\n" + "}", "class Foo {\n" +
+                                                                                                             "    int[] a = new int[]{\n" +
+                                                                                                             "            1, 2, 0x0052, 0x0053,\n" +
+                                                                                                             "            0x0054, 0x0054, 0x0054\n" +
+                                                                                                             "    };\n" +
+                                                                                                             "}");
   }
 
-  public void testSCRIDEA_4783() throws IncorrectOperationException {
-    getSettings().ASSIGNMENT_WRAP = CodeStyleSettings.WRAP_AS_NEEDED;
-    getSettings().METHOD_CALL_CHAIN_WRAP = CodeStyleSettings.WRAP_AS_NEEDED;
-    getSettings().RIGHT_MARGIN = 80;
+  public void testSpaceAfterCommaInEnum() throws IncorrectOperationException {
+    getSettings().SPACE_AFTER_COMMA = true;
 
-    doTextTest("class Foo{\n" +
-               "    void foo() {\n" +
-               "        final CommandRouterProtocolHandler protocolHandler = (CommandRouterProtocolHandler) connection.getProtocolHandler()\n" +
-               "    }\n" +
-"}", "class Foo {\n" +
-     "    void foo() {\n" +
-     "        final CommandRouterProtocolHandler protocolHandler =\n" +
-     "                (CommandRouterProtocolHandler) connection.getProtocolHandler()\n" +
-     "    }\n" +
-     "}");
-
-
-    doTextTest("class Foo{\n" +
-               "    void foo() {\n" +
-               "        protocolHandlerCommandRouterProtocolHandler = (CommandRouterProtocolHandler) connection.getProtocolHandler()\n" +
-               "    }\n" +
-"}", "class Foo {\n" +
-     "    void foo() {\n" +
-     "        protocolHandlerCommandRouterProtocolHandler =\n" +
-     "                (CommandRouterProtocolHandler) connection.getProtocolHandler()\n" +
-     "    }\n" +
-     "}");
+    final JavaPsiFacade facade = getJavaFacade();
+    final LanguageLevel effectiveLanguageLevel = LanguageLevelProjectExtension.getInstance(facade.getProject()).getLanguageLevel();
+    try {
+      LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
 
-    doTextTest("class Foo{\n" +
-               "    final CommandRouterProtocolHandler protocolHandler = (CommandRouterProtocolHandler) connection.getProtocolHandler()\n" +
-"}", "class Foo {\n" +
-     "    final CommandRouterProtocolHandler protocolHandler =\n" +
-     "            (CommandRouterProtocolHandler) connection.getProtocolHandler()\n" +
-     "}");
 
-    getSettings().PLACE_ASSIGNMENT_SIGN_ON_NEXT_LINE = true;
+      doTextTest("public enum StringExDirection {\n" + "\n" + "    RIGHT_TO_LEFT, LEFT_TO_RIGHT\n" + "\n" + "}",
+                 "public enum StringExDirection {\n" + "\n" + "    RIGHT_TO_LEFT, LEFT_TO_RIGHT\n" + "\n" + "}");
+    }
+    finally {
+      LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(effectiveLanguageLevel);
+    }
+  }
 
-    doTextTest("class Foo{\n" +
-               "    void foo() {\n" +
-               "        final CommandRouterProtocolHandler protocolHandler = (CommandRouterProtocolHandler) connection.getProtocolHandler()\n" +
+  public void testRemoveBraceBeforeInstanceOf() throws IncorrectOperationException {
+    doTextTest("class ReformatInstanceOf {\n" +
+               "    void foo(Object string) {\n" +
+               "        if (string.toString() instanceof String) {} // reformat me\n" +
                "    }\n" +
-"}", "class Foo {\n" +
-     "    void foo() {\n" +
-     "        final CommandRouterProtocolHandler protocolHandler\n" +
-     "                = (CommandRouterProtocolHandler) connection.getProtocolHandler()\n" +
+"}", "class ReformatInstanceOf {\n" +
+     "    void foo(Object string) {\n" +
+     "        if (string.toString() instanceof String) {\n" +
+     "        } // reformat me\n" +
      "    }\n" +
      "}");
+  }
 
-    doTextTest("class Foo{\n" +
-               "    void foo() {\n" +
-               "        protocolHandlerCommandRouterProtocolHandler = (CommandRouterProtocolHandler) connection.getProtocolHandler()\n" +
-               "    }\n" +
-"}", "class Foo {\n" +
-     "    void foo() {\n" +
-     "        protocolHandlerCommandRouterProtocolHandler\n" +
-     "                = (CommandRouterProtocolHandler) connection.getProtocolHandler()\n" +
-     "    }\n" +
-     "}");
+  public void testAnnotationBeforePackageLocalConstructor() throws IncorrectOperationException {
+    doTextTest("class Foo {\n" + "    @MyAnnotation Foo() {\n" + "    }\n" + "}",
+               "class Foo {\n" + "    @MyAnnotation\n" + "    Foo() {\n" + "    }\n" + "}");
+  }
 
+  public void testLongAnnotationsAreNotWrapped() throws Exception {
+    getSettings().ARRAY_INITIALIZER_WRAP = CodeStyleSettings.WRAP_AS_NEEDED;
+    doTest();
+  }
 
-    doTextTest("class Foo{\n" +
-               "    final CommandRouterProtocolHandler protocolHandler = (CommandRouterProtocolHandler) connection.getProtocolHandler()\n" +
-"}", "class Foo {\n" +
-     "    final CommandRouterProtocolHandler protocolHandler\n" +
-     "            = (CommandRouterProtocolHandler) connection.getProtocolHandler()\n" +
-     "}");
+  public void testWrapExtendsList() throws Exception {
+    getSettings().RIGHT_MARGIN = 50;
+    getSettings().EXTENDS_LIST_WRAP = CodeStyleSettings.WRAP_ON_EVERY_ITEM;
+    getSettings().EXTENDS_KEYWORD_WRAP = CodeStyleSettings.WRAP_AS_NEEDED;
 
+    doTextTest("class ColtreDataProvider extends DataProvider, AgentEventListener, ParameterDataEventListener {\n}",
+               "class ColtreDataProvider extends DataProvider,\n" +
+               "        AgentEventListener,\n" +
+               "        ParameterDataEventListener {\n}");
   }
 
-  public void testSCRIDEADEV_2292() throws IncorrectOperationException {
-    getSettings().KEEP_CONTROL_STATEMENT_IN_ONE_LINE = false;
-    getSettings().WHILE_ON_NEW_LINE = true;
-
-    final JavaPsiFacade facade = getJavaFacade();
-    final LanguageLevel stored = LanguageLevelProjectExtension.getInstance(facade.getProject()).getLanguageLevel();
-    LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
+  public void testWrapLongExpression() throws Exception {
+    getSettings().RIGHT_MARGIN = 80;
+    getSettings().BINARY_OPERATION_WRAP = CodeStyleSettings.WRAP_AS_NEEDED;
+    getSettings().ALIGN_MULTILINE_BINARY_OPERATION = true;
+    doTextTest("class Foo {\n" +
+               "    void foo () {\n" +
+               "        return (interval1.getEndIndex() >= interval2.getStartIndex() && interval3.getStartIndex() <= interval4.getEndIndex()) || (interval5.getEndIndex() >= interval6.getStartIndex() && interval7.getStartIndex() <= interval8.getEndIndex());" +
+               "    }\n" +
+               "}", "class Foo {\n" +
+                    "    void foo() {\n" +
+                    "        return (interval1.getEndIndex() >= interval2.getStartIndex() &&\n" +
+                    "                interval3.getStartIndex() <= interval4.getEndIndex()) ||\n" +
+                    "               (interval5.getEndIndex() >= interval6.getStartIndex() &&\n" +
+                    "                interval7.getStartIndex() <= interval8.getEndIndex());\n" +
+                    "    }\n" +
+                    "}");
+  }
 
-    try {
-      doTextTest("class Foo {\n" + "    void foo() {\n" + "        if (a) foo();\n" + "        else bar();\n" + "    }\n" + "}",
-                 "class Foo {\n" +
-                 "    void foo() {\n" +
-                 "        if (a)\n" +
-                 "            foo();\n" +
-                 "        else\n" +
-                 "            bar();\n" +
-                 "    }\n" +
-                 "}");
+  public void testDoNotWrapCallChainIfParametersWrapped() throws Exception {
+    getSettings().RIGHT_MARGIN = 87;
+    getSettings().CALL_PARAMETERS_WRAP = CodeStyleSettings.WRAP_AS_NEEDED;
+    getSettings().METHOD_CALL_CHAIN_WRAP = CodeStyleSettings.WRAP_AS_NEEDED;
+    getSettings().ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
+    //getSettings().PREFER_PARAMETERS_WRAP = true;
 
+    doMethodTest(
+      //9                    30                            70         80    86
+      "descriptors = manager.createProblemDescriptor(parameter1, parameter2, parameterparameterpar3,parameter4);",
 
-      doTextTest("class Foo {\n" + "    void foo() {\n" + "        for (int i = 0; i < 10; i++) foo();\n" + "    }\n" + "}",
-                 "class Foo {\n" +
-                 "    void foo() {\n" +
-                 "        for (int i = 0; i < 10; i++)\n" +
-                 "            foo();\n" +
-                 "    }\n" +
-                 "}");
+      "descriptors = manager.createProblemDescriptor(parameter1, parameter2,\n" +
+      "                                              parameterparameterpar3,\n" +
+      "                                              parameter4);"
 
+    );
+  }
 
-      doTextTest("class Foo {\n" + "    void foo() {\n" + "        for (int var : vars) foo();\n" + "    }\n" + "}",
-                 "class Foo {\n" + "    void foo() {\n" + "        for (int var : vars)\n" + "            foo();\n" + "    }\n" + "}");
+  public void testAlignTernaryOperation() throws Exception {
+    getSettings().ALIGN_MULTILINE_TERNARY_OPERATION = true;
+    doMethodTest("String s = x == 0 ? \"hello\" :\n" +
+                 "                x == 5 ? \"something else\" :\n" +
+                 "                        x > 0 ? \"bla, bla\" :\n" +
+                 "                                \"\";", "String s = x == 0 ? \"hello\" :\n" +
+                                                          "           x == 5 ? \"something else\" :\n" +
+                                                          "           x > 0 ? \"bla, bla\" :\n" +
+                                                          "           \"\";");
 
+    getSettings().TERNARY_OPERATION_SIGNS_ON_NEXT_LINE = true;
 
-      doTextTest("class Foo {\n" + "    void foo() {\n" + "        do foo(); while (true);\n" + "    }\n" + "}", "class Foo {\n" +
-                                                                                                                 "    void foo() {\n" +
-                                                                                                                 "        do\n" +
-                                                                                                                 "            foo();\n" +
-                                                                                                                 "        while (true);\n" +
-                                                                                                                 "    }\n" +
-                                                                                                                 "}");
+    doMethodTest("int someVariable = a ?\n" + "x :\n" + "y;",
+                 "int someVariable = a ?\n" + "                   x :\n" + "                   y;");
+  }
 
 
-      doTextTest("class Foo {\n" + "    void foo() {\n" + "        while(true) foo();\n" + "    }\n" + "}",
-                 "class Foo {\n" + "    void foo() {\n" + "        while (true)\n" + "            foo();\n" + "    }\n" + "}");
 
-      getSettings().KEEP_CONTROL_STATEMENT_IN_ONE_LINE = true;
-      getSettings().WHILE_ON_NEW_LINE = false;
+  public void testRightMargin() throws Exception {
+    getSettings().WRAP_COMMENTS = true;
+    getSettings().RIGHT_MARGIN = 35;//      |
+    doTextTest(
+      "/** Here is one-line java-doc comment */" +
+      "class Foo {\n" +
+      "}",
+      "/**\n" +
+      " * Here is one-line java-doc\n" +
+      " * comment\n" +
+      " */\n" +
+      "class Foo {\n" +
+      "}");
 
-      doTextTest("class Foo {\n" + "    void foo() {\n" + "        if (a) foo();\n" + "        else bar();\n" + "    }\n" + "}",
-                 "class Foo {\n" + "    void foo() {\n" + "        if (a) foo();\n" + "        else bar();\n" + "    }\n" + "}");
+  }
 
-      doTextTest("class Foo {\n" + "    void foo() {\n" + "        for (int i = 0; i < 10; i++) foo();\n" + "    }\n" + "}",
-                 "class Foo {\n" + "    void foo() {\n" + "        for (int i = 0; i < 10; i++) foo();\n" + "    }\n" + "}");
+  public void testRightMargin_2() throws Exception {
+    getSettings().RIGHT_MARGIN = 65;
+    getSettings().ASSIGNMENT_WRAP = CodeStyleSettings.WRAP_AS_NEEDED;
+    getSettings().PLACE_ASSIGNMENT_SIGN_ON_NEXT_LINE = true;
+    getSettings().KEEP_LINE_BREAKS = false;
 
+    doClassTest(
+      "public static final Map<LongType, LongType> longVariableName =\n" +
+      "variableValue;",
+      "public static final Map<LongType, LongType> longVariableName\n" +
+      "        = variableValue;");
+  }
 
-      doTextTest("class Foo {\n" + "    void foo() {\n" + "        for (int var : vars) foo();\n" + "    }\n" + "}",
-                 "class Foo {\n" + "    void foo() {\n" + "        for (int var : vars) foo();\n" + "    }\n" + "}");
+  public void testRightMargin_3() throws Exception {
+    getSettings().RIGHT_MARGIN = 65;
+    getSettings().ASSIGNMENT_WRAP = CodeStyleSettings.WRAP_AS_NEEDED;
+    getSettings().PLACE_ASSIGNMENT_SIGN_ON_NEXT_LINE = false;
+    getSettings().KEEP_LINE_BREAKS = false;
 
+    doClassTest(
+      "public static final Map<LongType, LongType> longVariableName =\n" +
+      "variableValue;",
+      "public static final Map<LongType, LongType>\n" +
+      "        longVariableName = variableValue;");
+  }
 
-      doTextTest("class Foo {\n" + "    void foo() {\n" + "        do foo(); while (true);\n" + "    }\n" + "}",
-                 "class Foo {\n" + "    void foo() {\n" + "        do foo(); while (true);\n" + "    }\n" + "}");
+  public void testDoNotRemoveLineBreaksBetweenComments(){
+    getSettings().KEEP_LINE_BREAKS = false;
+    getSettings().KEEP_FIRST_COLUMN_COMMENT = false;
 
+    doTextTest(
+      "public class Foo {\n" +
+      "   //here is a comment\n" +
+      "   //line 2 of comment\n" +
+      "   public void myMethod() {\n" +
+      "       //a comment\n" +
+      "       //... another comment\n" +
+      "   }\n" +
+      "\n" +
+      "//save for later\n" +
+      "//    public void incompleteMethod() {\n" +
+      "//        int blah = 0;\n" +
+      "//        callSomeMethod();\n" +
+      "//        callSomeOtherMethod();\n" +
+      "//        doSomethingElse();\n" +
+      "//    }\n" +
+      "\n" +
+      "//comment at first line\n" +
+      "}",
+      "public cla