From c7c7ad4781d2d54ba539faedf834ff80e97415c3 Mon Sep 17 00:00:00 2001 From: Alexander Kurtakov Date: Wed, 7 Oct 2015 15:48:00 +0300 Subject: No bug: Internalize SH UI packages. No API considered for now. Change-Id: I0f1d5ab538c962bdf37a9d59e0bd765fb859b550 Signed-off-by: Alexander Kurtakov --- .../org.eclipse.dltk.sh.ui/META-INF/MANIFEST.MF | 4 +- plugins/org.eclipse.dltk.sh.ui/plugin.xml | 56 ++-- .../org/eclipse/dltk/sh/internal/ui/Activator.java | 58 ++++ .../dltk/sh/internal/ui/IShellColorConstants.java | 27 ++ .../internal/ui/LaunchConfigurationDelegate.java | 23 ++ .../dltk/sh/internal/ui/LaunchShortcut.java | 29 ++ .../dltk/sh/internal/ui/MainPreferencePage.java | 48 +++ .../internal/ui/ShellContentAssistPreference.java | 31 ++ .../dltk/sh/internal/ui/ShellTodoParserType.java | 24 ++ .../sh/internal/ui/ShelledUILanguageToolkit.java | 34 ++ .../ui/ShelledUIPreferenceInitializer.java | 72 +++++ .../ui/commands/AbstractProjectHandler.java | 54 ++++ .../dltk/sh/internal/ui/commands/AddNature.java | 40 +++ .../internal/ui/commands/NaturePropertyTester.java | 42 +++ .../dltk/sh/internal/ui/commands/RemoveNature.java | 46 +++ .../sh/internal/ui/commands/ShowManHandler.java | 48 +++ .../ui/completion/ShellCompletionEngine.java | 76 +++++ .../ui/completion/ShellCompletionProcessor.java | 28 ++ .../ui/completion/ShellCompletionProposal.java | 43 +++ .../ShellCompletionProposalCollector.java | 57 ++++ .../ShellCompletionProposalComputer.java | 33 ++ .../ui/editor/ShellDocumentSetupParticipant.java | 26 ++ .../sh/internal/ui/editor/ShellScriptEditor.java | 67 ++++ .../ui/editor/ShellSourceViewerConfiguration.java | 233 ++++++++++++++ .../AddShellScriptInterpreterDialog.java | 30 ++ .../ShellInterpreterPreferencePage.java | 24 ++ .../ShellMainLaunchConfigurationTab.java | 38 +++ .../ui/interpreter/ShellScriptInstall.java | 34 ++ .../ui/interpreter/ShellScriptInstallType.java | 69 ++++ .../ShellScriptInterpreterLibraryBlock.java | 27 ++ .../interpreter/ShellScriptInterpretersBlock.java | 35 +++ .../sh/internal/ui/interpreter/ShellTabGroup.java | 28 ++ .../sh/internal/ui/preferences/PreviewFile.txt | 7 + .../ShellColoringConfigurationBlock.java | 92 ++++++ .../ui/preferences/ShellEditorPreferencesPage.java | 40 +++ .../ui/preferences/ShellFoldingPreferencePage.java | 56 ++++ .../ShellSyntaxColoringPreferencePage.java | 39 +++ .../preferences/ShellTodoTaskPreferencePage.java | 65 ++++ .../SimpleShellSourceViewerConfiguration.java | 93 ++++++ .../ui/search/ShelledMatchLocationParser.java | 27 ++ .../internal/ui/search/ShelledSearchFactory.java | 22 ++ .../sh/internal/ui/search/ShelledSearchPage.java | 22 ++ .../ui/selection/ShellDocumentationProvider.java | 33 ++ .../ui/selection/ShelledSelectionEngine.java | 89 ++++++ .../sh/internal/ui/text/AssignmentDetector.java | 31 ++ .../dltk/sh/internal/ui/text/AssignmentRule.java | 64 ++++ .../ui/text/DocumentAndCommandScanner.java | 65 ++++ .../internal/ui/text/DollarBraceCountingRule.java | 124 ++++++++ .../dltk/sh/internal/ui/text/DollarDetector.java | 27 ++ .../dltk/sh/internal/ui/text/DollarRule.java | 98 ++++++ .../sh/internal/ui/text/DoubleQuoteScanner.java | 69 ++++ .../dltk/sh/internal/ui/text/EvalScanner.java | 62 ++++ .../dltk/sh/internal/ui/text/IShellPartitions.java | 30 ++ .../dltk/sh/internal/ui/text/IndentType.java | 26 ++ .../internal/ui/text/ScriptAutoIndentStrategy.java | 346 +++++++++++++++++++++ .../dltk/sh/internal/ui/text/ShellCodeScanner.java | 119 +++++++ .../sh/internal/ui/text/ShellPartitionScanner.java | 60 ++++ .../dltk/sh/internal/ui/text/ShellTextTools.java | 40 +++ .../sh/internal/ui/text/WhitespaceDetector.java | 21 ++ .../internal/ui/text/folding/FoldingBlockKind.java | 22 ++ .../folding/ShellCodeFoldingBlockProvider.java | 68 ++++ .../folding/ShellCodeFoldingPreferenceBlock.java | 35 +++ .../folding/ShellCommentFoldingBlockProvider.java | 32 ++ .../ShellCommentFoldingPreferenceBlock.java | 43 +++ .../ui/wizards/NewShellScriptFilePage.java | 22 ++ .../ui/wizards/NewShellScriptFileWizard.java | 18 ++ .../ui/wizards/ShellScriptProjectWizard.java | 41 +++ .../src/org/eclipse/dltk/sh/ui/Activator.java | 58 ---- .../eclipse/dltk/sh/ui/IShellColorConstants.java | 27 -- .../dltk/sh/ui/LaunchConfigurationDelegate.java | 23 -- .../src/org/eclipse/dltk/sh/ui/LaunchShortcut.java | 29 -- .../org/eclipse/dltk/sh/ui/MainPreferencePage.java | 48 --- .../dltk/sh/ui/ShellContentAssistPreference.java | 31 -- .../eclipse/dltk/sh/ui/ShellTodoParserType.java | 24 -- .../dltk/sh/ui/ShelledUILanguageToolkit.java | 34 -- .../dltk/sh/ui/ShelledUIPreferenceInitializer.java | 72 ----- .../sh/ui/commands/AbstractProjectHandler.java | 54 ---- .../org/eclipse/dltk/sh/ui/commands/AddNature.java | 40 --- .../dltk/sh/ui/commands/NaturePropertyTester.java | 42 --- .../eclipse/dltk/sh/ui/commands/RemoveNature.java | 46 --- .../dltk/sh/ui/commands/ShowManHandler.java | 48 --- .../sh/ui/completion/ShellCompletionEngine.java | 76 ----- .../sh/ui/completion/ShellCompletionProcessor.java | 28 -- .../sh/ui/completion/ShellCompletionProposal.java | 43 --- .../ShellCompletionProposalCollector.java | 57 ---- .../ShellCompletionProposalComputer.java | 33 -- .../ui/editor/ShellDocumentSetupParticipant.java | 26 -- .../dltk/sh/ui/editor/ShellScriptEditor.java | 67 ---- .../ui/editor/ShellSourceViewerConfiguration.java | 233 -------------- .../AddShellScriptInterpreterDialog.java | 30 -- .../ShellInterpreterPreferencePage.java | 24 -- .../ShellMainLaunchConfigurationTab.java | 38 --- .../dltk/sh/ui/interpreter/ShellScriptInstall.java | 34 -- .../sh/ui/interpreter/ShellScriptInstallType.java | 69 ---- .../ShellScriptInterpreterLibraryBlock.java | 27 -- .../interpreter/ShellScriptInterpretersBlock.java | 35 --- .../dltk/sh/ui/interpreter/ShellTabGroup.java | 28 -- .../eclipse/dltk/sh/ui/preferences/PreviewFile.txt | 7 - .../ShellColoringConfigurationBlock.java | 92 ------ .../ui/preferences/ShellEditorPreferencesPage.java | 40 --- .../ui/preferences/ShellFoldingPreferencePage.java | 56 ---- .../ShellSyntaxColoringPreferencePage.java | 39 --- .../preferences/ShellTodoTaskPreferencePage.java | 65 ---- .../SimpleShellSourceViewerConfiguration.java | 93 ------ .../sh/ui/search/ShelledMatchLocationParser.java | 27 -- .../dltk/sh/ui/search/ShelledSearchFactory.java | 22 -- .../dltk/sh/ui/search/ShelledSearchPage.java | 22 -- .../ui/selection/ShellDocumentationProvider.java | 33 -- .../sh/ui/selection/ShelledSelectionEngine.java | 89 ------ .../dltk/sh/ui/text/AssignmentDetector.java | 31 -- .../eclipse/dltk/sh/ui/text/AssignmentRule.java | 64 ---- .../dltk/sh/ui/text/DocumentAndCommandScanner.java | 65 ---- .../dltk/sh/ui/text/DollarBraceCountingRule.java | 124 -------- .../eclipse/dltk/sh/ui/text/DollarDetector.java | 27 -- .../org/eclipse/dltk/sh/ui/text/DollarRule.java | 98 ------ .../dltk/sh/ui/text/DoubleQuoteScanner.java | 69 ---- .../org/eclipse/dltk/sh/ui/text/EvalScanner.java | 62 ---- .../eclipse/dltk/sh/ui/text/IShellPartitions.java | 30 -- .../org/eclipse/dltk/sh/ui/text/IndentType.java | 26 -- .../dltk/sh/ui/text/ScriptAutoIndentStrategy.java | 346 --------------------- .../eclipse/dltk/sh/ui/text/ShellCodeScanner.java | 119 ------- .../dltk/sh/ui/text/ShellPartitionScanner.java | 60 ---- .../eclipse/dltk/sh/ui/text/ShellTextTools.java | 40 --- .../dltk/sh/ui/text/WhitespaceDetector.java | 21 -- .../dltk/sh/ui/text/folding/FoldingBlockKind.java | 22 -- .../folding/ShellCodeFoldingBlockProvider.java | 68 ---- .../folding/ShellCodeFoldingPreferenceBlock.java | 35 --- .../folding/ShellCommentFoldingBlockProvider.java | 32 -- .../ShellCommentFoldingPreferenceBlock.java | 43 --- .../dltk/sh/ui/wizards/NewShellScriptFilePage.java | 22 -- .../sh/ui/wizards/NewShellScriptFileWizard.java | 18 -- .../sh/ui/wizards/ShellScriptProjectWizard.java | 41 --- tests/org.eclipse.dltk.sh.ui.tests/pom.xml | 4 +- .../dltk/sh/internal/ui/tests/AllTests.java | 24 ++ .../ui/text/tests/AbstractScannerTester.java | 71 +++++ .../internal/ui/text/tests/AssignmentRuleTest.java | 61 ++++ .../ui/text/tests/DollarBraceCountingRuleTest.java | 84 +++++ .../sh/internal/ui/text/tests/DollarRuleTest.java | 95 ++++++ .../ui/text/tests/DoubleQuoteScannerTest.java | 111 +++++++ .../sh/internal/ui/text/tests/EvalScannerTest.java | 73 +++++ .../sh/internal/ui/text/tests/MockScanner.java | 69 ++++ .../dltk/sh/internal/ui/text/tests/TextSuite.java | 24 ++ .../src/org/eclipse/dltk/sh/ui/tests/AllTests.java | 24 -- .../sh/ui/text/tests/AbstractScannerTester.java | 71 ----- .../dltk/sh/ui/text/tests/AssignmentRuleTest.java | 61 ---- .../ui/text/tests/DollarBraceCountingRuleTest.java | 84 ----- .../dltk/sh/ui/text/tests/DollarRuleTest.java | 95 ------ .../sh/ui/text/tests/DoubleQuoteScannerTest.java | 111 ------- .../dltk/sh/ui/text/tests/EvalScannerTest.java | 73 ----- .../eclipse/dltk/sh/ui/text/tests/MockScanner.java | 69 ---- .../eclipse/dltk/sh/ui/text/tests/TextSuite.java | 24 -- 151 files changed, 4115 insertions(+), 4117 deletions(-) create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/Activator.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/IShellColorConstants.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/LaunchConfigurationDelegate.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/LaunchShortcut.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/MainPreferencePage.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/ShellContentAssistPreference.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/ShellTodoParserType.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/ShelledUILanguageToolkit.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/ShelledUIPreferenceInitializer.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/commands/AbstractProjectHandler.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/commands/AddNature.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/commands/NaturePropertyTester.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/commands/RemoveNature.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/commands/ShowManHandler.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/completion/ShellCompletionEngine.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/completion/ShellCompletionProcessor.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/completion/ShellCompletionProposal.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/completion/ShellCompletionProposalCollector.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/completion/ShellCompletionProposalComputer.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/editor/ShellDocumentSetupParticipant.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/editor/ShellScriptEditor.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/editor/ShellSourceViewerConfiguration.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/AddShellScriptInterpreterDialog.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellInterpreterPreferencePage.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellMainLaunchConfigurationTab.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellScriptInstall.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellScriptInstallType.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellScriptInterpreterLibraryBlock.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellScriptInterpretersBlock.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellTabGroup.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/PreviewFile.txt create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/ShellColoringConfigurationBlock.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/ShellEditorPreferencesPage.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/ShellFoldingPreferencePage.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/ShellSyntaxColoringPreferencePage.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/ShellTodoTaskPreferencePage.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/SimpleShellSourceViewerConfiguration.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/search/ShelledMatchLocationParser.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/search/ShelledSearchFactory.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/search/ShelledSearchPage.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/selection/ShellDocumentationProvider.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/selection/ShelledSelectionEngine.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/AssignmentDetector.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/AssignmentRule.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/DocumentAndCommandScanner.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/DollarBraceCountingRule.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/DollarDetector.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/DollarRule.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/DoubleQuoteScanner.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/EvalScanner.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/IShellPartitions.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/IndentType.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ScriptAutoIndentStrategy.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ShellCodeScanner.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ShellPartitionScanner.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ShellTextTools.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/WhitespaceDetector.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/folding/FoldingBlockKind.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/folding/ShellCodeFoldingBlockProvider.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/folding/ShellCodeFoldingPreferenceBlock.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/folding/ShellCommentFoldingBlockProvider.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/folding/ShellCommentFoldingPreferenceBlock.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/wizards/NewShellScriptFilePage.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/wizards/NewShellScriptFileWizard.java create mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/wizards/ShellScriptProjectWizard.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/Activator.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/IShellColorConstants.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/LaunchConfigurationDelegate.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/LaunchShortcut.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/MainPreferencePage.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/ShellContentAssistPreference.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/ShellTodoParserType.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/ShelledUILanguageToolkit.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/ShelledUIPreferenceInitializer.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/commands/AbstractProjectHandler.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/commands/AddNature.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/commands/NaturePropertyTester.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/commands/RemoveNature.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/commands/ShowManHandler.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/completion/ShellCompletionEngine.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/completion/ShellCompletionProcessor.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/completion/ShellCompletionProposal.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/completion/ShellCompletionProposalCollector.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/completion/ShellCompletionProposalComputer.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/editor/ShellDocumentSetupParticipant.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/editor/ShellScriptEditor.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/editor/ShellSourceViewerConfiguration.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/AddShellScriptInterpreterDialog.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellInterpreterPreferencePage.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellMainLaunchConfigurationTab.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellScriptInstall.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellScriptInstallType.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellScriptInterpreterLibraryBlock.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellScriptInterpretersBlock.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellTabGroup.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/PreviewFile.txt delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/ShellColoringConfigurationBlock.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/ShellEditorPreferencesPage.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/ShellFoldingPreferencePage.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/ShellSyntaxColoringPreferencePage.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/ShellTodoTaskPreferencePage.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/SimpleShellSourceViewerConfiguration.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/search/ShelledMatchLocationParser.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/search/ShelledSearchFactory.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/search/ShelledSearchPage.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/selection/ShellDocumentationProvider.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/selection/ShelledSelectionEngine.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/AssignmentDetector.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/AssignmentRule.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/DocumentAndCommandScanner.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/DollarBraceCountingRule.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/DollarDetector.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/DollarRule.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/DoubleQuoteScanner.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/EvalScanner.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/IShellPartitions.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/IndentType.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/ScriptAutoIndentStrategy.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/ShellCodeScanner.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/ShellPartitionScanner.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/ShellTextTools.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/WhitespaceDetector.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/folding/FoldingBlockKind.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/folding/ShellCodeFoldingBlockProvider.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/folding/ShellCodeFoldingPreferenceBlock.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/folding/ShellCommentFoldingBlockProvider.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/folding/ShellCommentFoldingPreferenceBlock.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/wizards/NewShellScriptFilePage.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/wizards/NewShellScriptFileWizard.java delete mode 100644 plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/wizards/ShellScriptProjectWizard.java create mode 100644 tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/tests/AllTests.java create mode 100644 tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/AbstractScannerTester.java create mode 100644 tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/AssignmentRuleTest.java create mode 100644 tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/DollarBraceCountingRuleTest.java create mode 100644 tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/DollarRuleTest.java create mode 100644 tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/DoubleQuoteScannerTest.java create mode 100644 tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/EvalScannerTest.java create mode 100644 tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/MockScanner.java create mode 100644 tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/TextSuite.java delete mode 100644 tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/tests/AllTests.java delete mode 100644 tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/AbstractScannerTester.java delete mode 100644 tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/AssignmentRuleTest.java delete mode 100644 tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/DollarBraceCountingRuleTest.java delete mode 100644 tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/DollarRuleTest.java delete mode 100644 tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/DoubleQuoteScannerTest.java delete mode 100644 tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/EvalScannerTest.java delete mode 100644 tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/MockScanner.java delete mode 100644 tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/TextSuite.java diff --git a/plugins/org.eclipse.dltk.sh.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.dltk.sh.ui/META-INF/MANIFEST.MF index bca544a..1e7b5bb 100644 --- a/plugins/org.eclipse.dltk.sh.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.dltk.sh.ui/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: ShellEd UI Plug-in Bundle-SymbolicName: org.eclipse.dltk.sh.ui;singleton:=true Bundle-Version: 5.4.0.qualifier -Bundle-Activator: org.eclipse.dltk.sh.ui.Activator +Bundle-Activator: org.eclipse.dltk.sh.internal.ui.Activator Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.eclipse.dltk.ui;bundle-version="[4.0.0,6.0.0)", @@ -19,6 +19,4 @@ Require-Bundle: org.eclipse.ui, org.eclipse.core.expressions Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.7 -Export-Package: org.eclipse.dltk.sh.ui, - org.eclipse.dltk.sh.ui.text Bundle-Vendor: Eclipse.org diff --git a/plugins/org.eclipse.dltk.sh.ui/plugin.xml b/plugins/org.eclipse.dltk.sh.ui/plugin.xml index 787b8e1..9e26147 100644 --- a/plugins/org.eclipse.dltk.sh.ui/plugin.xml +++ b/plugins/org.eclipse.dltk.sh.ui/plugin.xml @@ -2,7 +2,7 @@ - @@ -11,7 +11,7 @@ @@ -50,36 +50,36 @@ + class="org.eclipse.dltk.sh.internal.ui.MainPreferencePage"> + class="org.eclipse.dltk.sh.internal.ui.ShelledUIPreferenceInitializer" /> @@ -107,7 +107,7 @@ - @@ -130,20 +130,20 @@ @@ -151,20 +151,20 @@ @@ -178,7 +178,7 @@ nature="org.eclipse.dltk.sh.core.nature"> @@ -190,7 +190,7 @@ @@ -199,19 +199,19 @@ categoryId="org.eclipse.debug.ui.category.run" id="org.eclipse.dltk.sh.ui.shortcut"> @@ -292,7 +292,7 @@ + class="org.eclipse.dltk.sh.internal.ui.text.folding.ShellCommentFoldingBlockProvider"> + class="org.eclipse.dltk.sh.internal.ui.text.folding.ShellCodeFoldingBlockProvider"> diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/Activator.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/Activator.java new file mode 100644 index 0000000..4d59082 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/Activator.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui; + +import org.eclipse.dltk.sh.internal.ui.text.ShellTextTools; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The shared instance + private static Activator plugin; + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.dltk.sh.ui"; + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + private ShellTextTools fShellTextTools; + + public synchronized ShellTextTools getTextTools() { + if (fShellTextTools == null) { + fShellTextTools = new ShellTextTools(true); + } + return fShellTextTools; + } + + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/IShellColorConstants.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/IShellColorConstants.java new file mode 100644 index 0000000..292f219 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/IShellColorConstants.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui; + +import org.eclipse.dltk.ui.text.DLTKColorConstants; + +public interface IShellColorConstants { + String SHELL_COMMENT = DLTKColorConstants.DLTK_SINGLE_LINE_COMMENT; + String SHELL_DEFAULT = DLTKColorConstants.DLTK_DEFAULT; + String SHELL_DOUBLE_QUOTE = "SHELLED_interpolated_string"; + String SHELL_EVAL = DLTKColorConstants.DLTK_OPERATOR; + String SHELL_FUNCTION = DLTKColorConstants.DLTK_FUNCTION_DEFINITION; + String SHELL_HASHBANG = DLTKColorConstants.DLTK_MULTI_LINE_COMMENT; + String SHELL_KEYWORD = DLTKColorConstants.DLTK_KEYWORD; + String SHELL_SINGLE_QUOTE = DLTKColorConstants.DLTK_STRING; + String SHELL_VARIABLE = DLTKColorConstants.DLTK_ARGUMENT; + String SHELL_COMMAND = DLTKColorConstants.DLTK_BASE_CLASS; + String SHELL_TODO_TAG = DLTKColorConstants.TASK_TAG; +} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/LaunchConfigurationDelegate.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/LaunchConfigurationDelegate.java new file mode 100644 index 0000000..21552a8 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/LaunchConfigurationDelegate.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui; + +import org.eclipse.dltk.launching.AbstractScriptLaunchConfigurationDelegate; +import org.eclipse.dltk.sh.core.ShelledNature; + +public class LaunchConfigurationDelegate extends AbstractScriptLaunchConfigurationDelegate { + + @Override + public String getLanguageId() { + return ShelledNature.SHELLED_NATURE; + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/LaunchShortcut.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/LaunchShortcut.java new file mode 100644 index 0000000..44f556e --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/LaunchShortcut.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui; + +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.dltk.internal.debug.ui.launcher.AbstractScriptLaunchShortcut; +import org.eclipse.dltk.sh.core.ShelledNature; + +public class LaunchShortcut extends AbstractScriptLaunchShortcut { + + @Override + protected ILaunchConfigurationType getConfigurationType() { + return getLaunchManager().getLaunchConfigurationType("org.eclipse.dltk.sh.ui.launchConfigurationType1"); + } + + @Override + protected String getNatureId() { + return ShelledNature.SHELLED_NATURE; + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/MainPreferencePage.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/MainPreferencePage.java new file mode 100644 index 0000000..c363c50 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/MainPreferencePage.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui; + +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +public class MainPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { + + public MainPreferencePage() { + // TODO Auto-generated constructor stub + } + + public MainPreferencePage(String title) { + super(title); + // TODO Auto-generated constructor stub + } + + public MainPreferencePage(String title, ImageDescriptor image) { + super(title, image); + // TODO Auto-generated constructor stub + } + + @Override + protected Control createContents(Composite parent) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void init(IWorkbench workbench) { + // TODO Auto-generated method stub + + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/ShellContentAssistPreference.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/ShellContentAssistPreference.java new file mode 100644 index 0000000..fd387a2 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/ShellContentAssistPreference.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui; + +import org.eclipse.dltk.ui.text.ScriptTextTools; +import org.eclipse.dltk.ui.text.completion.ContentAssistPreference; + +public class ShellContentAssistPreference extends ContentAssistPreference { + private static ShellContentAssistPreference instance; + + public static ContentAssistPreference getDefault() { + if (instance == null) { + instance = new ShellContentAssistPreference(); + } + return instance; + } + + @Override + protected ScriptTextTools getTextTools() { + return Activator.getDefault().getTextTools(); + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/ShellTodoParserType.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/ShellTodoParserType.java new file mode 100644 index 0000000..da420ec --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/ShellTodoParserType.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui; + +import org.eclipse.dltk.compiler.task.ITodoTaskPreferences; +import org.eclipse.dltk.compiler.task.TodoTaskPreferencesOnPreferenceLookupDelegate; +import org.eclipse.dltk.core.IScriptProject; +import org.eclipse.dltk.core.builder.AbstractTodoTaskBuildParticipantType; + +public class ShellTodoParserType extends AbstractTodoTaskBuildParticipantType { + + @Override + protected ITodoTaskPreferences getPreferences(IScriptProject project) { + return new TodoTaskPreferencesOnPreferenceLookupDelegate(Activator.PLUGIN_ID, project); + } +} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/ShelledUILanguageToolkit.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/ShelledUILanguageToolkit.java new file mode 100644 index 0000000..c571aa7 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/ShelledUILanguageToolkit.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui; + +import org.eclipse.dltk.core.IDLTKLanguageToolkit; +import org.eclipse.dltk.sh.core.ShellScriptLanguageToolkit; +import org.eclipse.dltk.sh.internal.ui.interpreter.ShellInterpreterPreferencePage; +import org.eclipse.dltk.ui.AbstractDLTKUILanguageToolkit; +import org.eclipse.jface.preference.IPreferenceStore; + +public class ShelledUILanguageToolkit extends AbstractDLTKUILanguageToolkit { + @Override + public IDLTKLanguageToolkit getCoreToolkit() { + return ShellScriptLanguageToolkit.getDefault(); + } + + @Override + public IPreferenceStore getPreferenceStore() { + return Activator.getDefault().getPreferenceStore(); + } + + @Override + public String getInterpreterPreferencePage() { + return ShellInterpreterPreferencePage.PAGE_ID; + } +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/ShelledUIPreferenceInitializer.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/ShelledUIPreferenceInitializer.java new file mode 100644 index 0000000..9786da6 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/ShelledUIPreferenceInitializer.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui; + +import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; +import org.eclipse.core.runtime.preferences.DefaultScope; +import org.eclipse.dltk.compiler.task.TaskTagUtils; +import org.eclipse.dltk.ui.CodeFormatterConstants; +import org.eclipse.dltk.ui.PreferenceConstants; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceConverter; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.ui.editors.text.EditorsUI; + +public class ShelledUIPreferenceInitializer extends AbstractPreferenceInitializer { + + @Override + public void initializeDefaultPreferences() { + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + + EditorsUI.useAnnotationsPreferencePage(store); + EditorsUI.useQuickDiffPreferencePage(store); + + // Initialize DLTK default values + PreferenceConstants.initializeDefaultValues(store); + + // Initialize SHELL constants + PreferenceConverter.setDefault(store, IShellColorConstants.SHELL_COMMENT, new RGB(136, 0, 136)); + PreferenceConverter.setDefault(store, IShellColorConstants.SHELL_HASHBANG, new RGB(136, 136, 136)); + PreferenceConverter.setDefault(store, IShellColorConstants.SHELL_KEYWORD, new RGB(144, 4, 86)); + PreferenceConverter.setDefault(store, IShellColorConstants.SHELL_SINGLE_QUOTE, new RGB(13, 109, 160)); + PreferenceConverter.setDefault(store, IShellColorConstants.SHELL_DOUBLE_QUOTE, new RGB(13, 109, 24)); + PreferenceConverter.setDefault(store, IShellColorConstants.SHELL_EVAL, new RGB(205, 30, 30)); + PreferenceConverter.setDefault(store, IShellColorConstants.SHELL_FUNCTION, new RGB(255, 127, 63)); + PreferenceConverter.setDefault(store, IShellColorConstants.SHELL_COMMAND, new RGB(255, 127, 63)); + PreferenceConverter.setDefault(store, IShellColorConstants.SHELL_VARIABLE, new RGB(0, 0, 156)); + + PreferenceConverter.setDefault(store, IShellColorConstants.SHELL_TODO_TAG, new RGB(127, 159, 191)); + store.setDefault(IShellColorConstants.SHELL_TODO_TAG + PreferenceConstants.EDITOR_BOLD_SUFFIX, true); + + store.setDefault(IShellColorConstants.SHELL_COMMENT + PreferenceConstants.EDITOR_BOLD_SUFFIX, false); + store.setDefault(IShellColorConstants.SHELL_COMMENT + PreferenceConstants.EDITOR_ITALIC_SUFFIX, true); + store.setDefault(IShellColorConstants.SHELL_HASHBANG + PreferenceConstants.EDITOR_ITALIC_SUFFIX, true); + + store.setDefault(IShellColorConstants.SHELL_KEYWORD + PreferenceConstants.EDITOR_BOLD_SUFFIX, true); + store.setDefault(IShellColorConstants.SHELL_KEYWORD + PreferenceConstants.EDITOR_ITALIC_SUFFIX, false); + + store.setDefault(PreferenceConstants.EDITOR_TAB_WIDTH, 8); + store.setDefault(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE, true); + + store.setDefault(CodeFormatterConstants.FORMATTER_TAB_CHAR, CodeFormatterConstants.TAB); + store.setDefault(CodeFormatterConstants.FORMATTER_TAB_SIZE, "4"); + store.setDefault(CodeFormatterConstants.FORMATTER_INDENTATION_SIZE, "4"); + + /* folding */ + store.setDefault(PreferenceConstants.EDITOR_FOLDING_ENABLED, true); + store.setDefault(PreferenceConstants.EDITOR_FOLDING_LINES_LIMIT, 2); + store.setDefault(PreferenceConstants.EDITOR_COMMENTS_FOLDING_ENABLED, true); + store.setDefault(PreferenceConstants.EDITOR_DOCS_FOLDING_ENABLED, true); + store.setDefault(PreferenceConstants.EDITOR_FOLDING_INIT_COMMENTS, true); + + TaskTagUtils.initializeDefaultValues(DefaultScope.INSTANCE.getNode(Activator.PLUGIN_ID)); + } +} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/commands/AbstractProjectHandler.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/commands/AbstractProjectHandler.java new file mode 100644 index 0000000..dbdcbd6 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/commands/AbstractProjectHandler.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2010 Mat Booth and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.commands; + +import java.util.Iterator; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * An abstract command handler that iterates through the current selection + * looking for projects resources to save us from having this code in every + * handler that wants to manipulate projects. + */ +public abstract class AbstractProjectHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) { + IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event); + Iterator iterator = selection.iterator(); + while (iterator.hasNext()) { + Object element = iterator.next(); + IProject project = null; + if (element instanceof IProject) { + project = (IProject) element; + } else if (element instanceof IAdaptable) { + project = (IProject)((IAdaptable) element).getAdapter(IProject.class); + } + if (project != null) { + fettleProject(project); + } + } + return null; + } + + /** + * To be implemented by sub-classes to perform actions on a project. This + * will be called once for every project resource that is currently + * selected. + * + * @param project + * a project resource for manipulation + */ + protected abstract void fettleProject(IProject project); +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/commands/AddNature.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/commands/AddNature.java new file mode 100644 index 0000000..24b7f23 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/commands/AddNature.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2010 Mat Booth and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.commands; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.dltk.sh.core.ShelledNature; + +/** + * Implementation of the project handler that adds the ShellEd nature to a + * project. + */ +public class AddNature extends AbstractProjectHandler { + + @Override + protected void fettleProject(IProject project) { + try { + // Get the project description + IProjectDescription description = project.getDescription(); + String[] natures = description.getNatureIds(); + + // Add the nature to the list + String[] newNatures = new String[natures.length + 1]; + System.arraycopy(natures, 0, newNatures, 0, natures.length); + newNatures[natures.length] = ShelledNature.SHELLED_NATURE; + + // Set the project description + description.setNatureIds(newNatures); + project.setDescription(description, null); + } catch (CoreException e) { + e.printStackTrace(); + } + } +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/commands/NaturePropertyTester.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/commands/NaturePropertyTester.java new file mode 100644 index 0000000..eb92e3f --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/commands/NaturePropertyTester.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2010 Mat Booth and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.commands; + +import org.eclipse.core.expressions.PropertyTester; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.dltk.sh.core.ShelledNature; + +/** + * A property tester that returns true if the project containing any given + * resource is a ShellEd-natured project. + */ +public class NaturePropertyTester extends PropertyTester { + + // Properties made available for test by this tester + private static final String HAS_SHELLED_NATURE = "hasShellEdNature"; //$NON-NLS-1$ + + @Override + public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { + IResource resource = (IResource)((IAdaptable) receiver).getAdapter(IResource.class); + if (resource == null) { + return false; + } + if (property.equals(HAS_SHELLED_NATURE)) { + try { + IProject proj = resource.getProject(); + return proj.isAccessible() && proj.hasNature(ShelledNature.SHELLED_NATURE); + } catch (CoreException e) { + return false; + } + } + return false; + } +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/commands/RemoveNature.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/commands/RemoveNature.java new file mode 100644 index 0000000..61a0f5d --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/commands/RemoveNature.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2010 Mat Booth and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.commands; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.dltk.sh.core.ShelledNature; + +/** + * Implementation of the project handler that removes the ShellEd nature from a + * project. + */ +public class RemoveNature extends AbstractProjectHandler { + + @Override + protected void fettleProject(IProject project) { + try { + // Get the project description + IProjectDescription description = project.getDescription(); + String[] natures = description.getNatureIds(); + + // Filter the nature out of the list + List newNatures = new ArrayList<>(); + for (String nature : natures) { + if (!ShelledNature.SHELLED_NATURE.equals(nature)) { + newNatures.add(nature); + } + } + + // Set the project description + description.setNatureIds(newNatures.toArray(new String[newNatures.size()])); + project.setDescription(description, null); + } catch (CoreException e) { + e.printStackTrace(); + } + } +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/commands/ShowManHandler.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/commands/ShowManHandler.java new file mode 100644 index 0000000..e681168 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/commands/ShowManHandler.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.commands; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.jface.text.TextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.linuxtools.man.views.ManView; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * A command handler that opens the Man Page view and tries to show the man page + * for whatever text is currently highlighted. + */ +public class ShowManHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) { + try { + ISelection selection = HandlerUtil.getActiveEditor(event).getEditorSite().getSelectionProvider() + .getSelection(); + String manPage = ""; + if (selection instanceof TextSelection) { + TextSelection textSelection = (TextSelection) selection; + manPage = textSelection.getText(); + } + + if (!manPage.isEmpty()) { + ManView view = (ManView) HandlerUtil.getActiveWorkbenchWindow(event).getActivePage() + .showView(ManView.ID); + view.setManPageName(manPage); + } + } catch (PartInitException e) { + e.printStackTrace(); + } + return null; + } +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/completion/ShellCompletionEngine.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/completion/ShellCompletionEngine.java new file mode 100644 index 0000000..d0db3e6 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/completion/ShellCompletionEngine.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.completion; + +import org.eclipse.dltk.codeassist.ScriptCompletionEngine; +import org.eclipse.dltk.compiler.env.IModuleSource; +import org.eclipse.dltk.core.CompletionProposal; +import org.eclipse.dltk.core.DLTKCore; +import org.eclipse.dltk.core.IModelElement; +import org.eclipse.dltk.core.IModelElementVisitor; +import org.eclipse.dltk.core.ModelException; +import org.eclipse.dltk.sh.internal.ui.text.ShellCodeScanner; + +public class ShellCompletionEngine extends ScriptCompletionEngine { + + private int actualCompletionPosition; + + @Override + public void complete(IModuleSource module, int position, int pos) { + + this.actualCompletionPosition = position; + this.offset = pos; + String temp = module.getSourceContents().substring(0, position); + int lastSpace = temp.lastIndexOf(' '); + int lastNewline = temp.lastIndexOf('\n'); + String complPrefix = temp.substring(lastSpace > lastNewline ? lastSpace : lastNewline).trim(); + this.requestor.beginReporting(); + for (String keyword : ShellCodeScanner.KEYWORDS) { + if (keyword.startsWith(complPrefix)) { + createProposal(keyword, null); + } + } + for (String command : ShellCodeScanner.getCommands()) { + if (command.startsWith(complPrefix)) { + createProposal(command, null); + } + } + + // Completion for model elements. + try { + module.getModelElement().accept(new IModelElementVisitor() { + @Override + public boolean visit(IModelElement element) { + if (element.getElementType() > IModelElement.SOURCE_MODULE) { + createProposal(element.getElementName(), element); + } + return true; + } + }); + } catch (ModelException e) { + if (DLTKCore.DEBUG) { + e.printStackTrace(); + } + } + this.requestor.endReporting(); + } + + private void createProposal(String name, IModelElement element) { + CompletionProposal proposal = this.createProposal(CompletionProposal.KEYWORD, this.actualCompletionPosition); + proposal.setName(name); + proposal.setCompletion(name); + proposal.setReplaceRange(actualCompletionPosition - offset, actualCompletionPosition - offset); + proposal.setRelevance(20); + proposal.setModelElement(element); + this.requestor.accept(proposal); + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/completion/ShellCompletionProcessor.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/completion/ShellCompletionProcessor.java new file mode 100644 index 0000000..3aa3d91 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/completion/ShellCompletionProcessor.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.completion; + +import org.eclipse.dltk.sh.core.ShelledNature; +import org.eclipse.dltk.ui.text.completion.ScriptCompletionProcessor; +import org.eclipse.jface.text.contentassist.ContentAssistant; +import org.eclipse.ui.IEditorPart; + +public class ShellCompletionProcessor extends ScriptCompletionProcessor { + public ShellCompletionProcessor(IEditorPart editor, ContentAssistant assistant, String partition) { + super(editor, assistant, partition); + } + + @Override + protected String getNatureId() { + return ShelledNature.SHELLED_NATURE; + } + +} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/completion/ShellCompletionProposal.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/completion/ShellCompletionProposal.java new file mode 100644 index 0000000..b58b48f --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/completion/ShellCompletionProposal.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.completion; + +import org.eclipse.dltk.sh.internal.ui.Activator; +import org.eclipse.dltk.ui.PreferenceConstants; +import org.eclipse.dltk.ui.text.completion.ScriptCompletionProposal; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.swt.graphics.Image; + +public class ShellCompletionProposal extends ScriptCompletionProposal { + public ShellCompletionProposal(String replacementString, int replacementOffset, int replacementLength, Image image, + String displayString, int relevance) { + super(replacementString, replacementOffset, replacementLength, image, displayString, relevance); + } + + public ShellCompletionProposal(String replacementString, int replacementOffset, int replacementLength, Image image, + String displayString, int relevance, boolean isInDoc) { + super(replacementString, replacementOffset, replacementLength, image, displayString, relevance, isInDoc); + } + + @Override + protected boolean isSmartTrigger(char trigger) { + if (trigger == '$') { + return true; + } + return false; + } + + @Override + protected boolean insertCompletion() { + IPreferenceStore preference = Activator.getDefault().getPreferenceStore(); + return preference.getBoolean(PreferenceConstants.CODEASSIST_INSERT_COMPLETION); + } +} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/completion/ShellCompletionProposalCollector.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/completion/ShellCompletionProposalCollector.java new file mode 100644 index 0000000..6d0b2ab --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/completion/ShellCompletionProposalCollector.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.completion; + +import org.eclipse.dltk.core.IScriptProject; +import org.eclipse.dltk.core.ISourceModule; +import org.eclipse.dltk.ui.text.completion.ScriptCompletionProposal; +import org.eclipse.dltk.ui.text.completion.ScriptCompletionProposalCollector; +import org.eclipse.swt.graphics.Image; + +public class ShellCompletionProposalCollector extends ScriptCompletionProposalCollector { + + public ShellCompletionProposalCollector(ISourceModule module) { + super(module); + } + + @Override + protected ScriptCompletionProposal createOverrideCompletionProposal(IScriptProject scriptProject, + ISourceModule compilationUnit, String name, String[] paramTypes, int start, int length, String label, + String string) { + // TODO Auto-generated method stub + return null; + } + + @Override + protected ScriptCompletionProposal createScriptCompletionProposal(String completion, int replaceStart, int length, + Image image, String displayString, int i) { + return new ShellCompletionProposal(completion, replaceStart, length, image, displayString, i); + + } + + @Override + protected ScriptCompletionProposal createScriptCompletionProposal(String completion, int replaceStart, int length, + Image image, String displayString, int i, boolean isInDoc) { + return new ShellCompletionProposal(completion, replaceStart, length, image, displayString, i); + } + + @Override + protected char[] getVarTrigger() { + return new char[] { '$' }; + } + + @Override + protected String getNatureId() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/completion/ShellCompletionProposalComputer.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/completion/ShellCompletionProposalComputer.java new file mode 100644 index 0000000..8e860d9 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/completion/ShellCompletionProposalComputer.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.completion; + +import org.eclipse.dltk.ui.text.completion.ScriptCompletionProposalCollector; +import org.eclipse.dltk.ui.text.completion.ScriptCompletionProposalComputer; +import org.eclipse.dltk.ui.text.completion.ScriptContentAssistInvocationContext; +import org.eclipse.jface.text.templates.TemplateCompletionProcessor; + +public class ShellCompletionProposalComputer extends ScriptCompletionProposalComputer { + + public ShellCompletionProposalComputer() { + + } + + @Override + protected ScriptCompletionProposalCollector createCollector(ScriptContentAssistInvocationContext context) { + return new ShellCompletionProposalCollector(context.getSourceModule()); + } + + @Override + protected TemplateCompletionProcessor createTemplateProposalComputer(ScriptContentAssistInvocationContext context) { + return null; + } +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/editor/ShellDocumentSetupParticipant.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/editor/ShellDocumentSetupParticipant.java new file mode 100644 index 0000000..6d73e3e --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/editor/ShellDocumentSetupParticipant.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.editor; + +import org.eclipse.core.filebuffers.IDocumentSetupParticipant; +import org.eclipse.dltk.sh.internal.ui.Activator; +import org.eclipse.dltk.sh.internal.ui.text.IShellPartitions; +import org.eclipse.dltk.sh.internal.ui.text.ShellTextTools; +import org.eclipse.jface.text.IDocument; + +public class ShellDocumentSetupParticipant implements IDocumentSetupParticipant { + + @Override + public void setup(IDocument document) { + ShellTextTools tools = Activator.getDefault().getTextTools(); + tools.setupDocumentPartitioner(document, IShellPartitions.SHELL_PARTITIONING); + } +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/editor/ShellScriptEditor.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/editor/ShellScriptEditor.java new file mode 100644 index 0000000..94589c0 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/editor/ShellScriptEditor.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.editor; + +import org.eclipse.dltk.core.IDLTKLanguageToolkit; +import org.eclipse.dltk.internal.ui.editor.ScriptEditor; +import org.eclipse.dltk.sh.core.ShellScriptLanguageToolkit; +import org.eclipse.dltk.sh.internal.ui.Activator; +import org.eclipse.dltk.sh.internal.ui.text.IShellPartitions; +import org.eclipse.dltk.ui.text.ScriptTextTools; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentExtension3; +import org.eclipse.ui.IEditorInput; + +public class ShellScriptEditor extends ScriptEditor { + + public static final String EDITOR_CONTEXT = "#ShellScriptEditorContext"; + + public static final String EDITOR_ID = "org.eclipse.dltk.sh.ui.editor"; + + @Override + protected void connectPartitioningToElement(IEditorInput input, IDocument document) { + if (document instanceof IDocumentExtension3) { + IDocumentExtension3 extension = (IDocumentExtension3) document; + if (extension.getDocumentPartitioner(IShellPartitions.SHELL_PARTITIONING) == null) { + ShellDocumentSetupParticipant participant = new ShellDocumentSetupParticipant(); + participant.setup(document); + } + } + } + + @Override + public String getEditorId() { + return EDITOR_ID; + } + + @Override + public IDLTKLanguageToolkit getLanguageToolkit() { + return ShellScriptLanguageToolkit.getDefault(); + } + + @Override + public IPreferenceStore getScriptPreferenceStore() { + return Activator.getDefault().getPreferenceStore(); + } + + @Override + public ScriptTextTools getTextTools() { + return Activator.getDefault().getTextTools(); + } + + @Override + protected void initializeEditor() { + super.initializeEditor(); + setEditorContextMenuId(EDITOR_CONTEXT); + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/editor/ShellSourceViewerConfiguration.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/editor/ShellSourceViewerConfiguration.java new file mode 100644 index 0000000..16e6368 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/editor/ShellSourceViewerConfiguration.java @@ -0,0 +1,233 @@ +/******************************************************************************* + * Copyright (c) 2009-2010 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.editor; + +import java.util.ArrayList; + +import org.eclipse.dltk.sh.internal.ui.Activator; +import org.eclipse.dltk.sh.internal.ui.IShellColorConstants; +import org.eclipse.dltk.sh.internal.ui.ShellContentAssistPreference; +import org.eclipse.dltk.sh.internal.ui.completion.ShellCompletionProcessor; +import org.eclipse.dltk.sh.internal.ui.text.DoubleQuoteScanner; +import org.eclipse.dltk.sh.internal.ui.text.EvalScanner; +import org.eclipse.dltk.sh.internal.ui.text.IShellPartitions; +import org.eclipse.dltk.sh.internal.ui.text.IndentType; +import org.eclipse.dltk.sh.internal.ui.text.ScriptAutoIndentStrategy; +import org.eclipse.dltk.sh.internal.ui.text.ShellCodeScanner; +import org.eclipse.dltk.sh.internal.ui.text.WhitespaceDetector; +import org.eclipse.dltk.ui.text.AbstractScriptScanner; +import org.eclipse.dltk.ui.text.IColorManager; +import org.eclipse.dltk.ui.text.ScriptOutlineInformationControl; +import org.eclipse.dltk.ui.text.ScriptPresentationReconciler; +import org.eclipse.dltk.ui.text.ScriptSourceViewerConfiguration; +import org.eclipse.dltk.ui.text.SingleTokenScriptScanner; +import org.eclipse.dltk.ui.text.completion.ContentAssistPreference; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.IAutoEditStrategy; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IInformationControl; +import org.eclipse.jface.text.IInformationControlCreator; +import org.eclipse.jface.text.contentassist.ContentAssistant; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.text.presentation.IPresentationReconciler; +import org.eclipse.jface.text.presentation.PresentationReconciler; +import org.eclipse.jface.text.rules.DefaultDamagerRepairer; +import org.eclipse.jface.text.rules.IRule; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.IWordDetector; +import org.eclipse.jface.text.rules.Token; +import org.eclipse.jface.text.rules.WhitespaceRule; +import org.eclipse.jface.text.rules.WordRule; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.texteditor.ITextEditor; + +public class ShellSourceViewerConfiguration extends ScriptSourceViewerConfiguration { + + private static IRule getKeywords(IToken keywordToken, final String[] words, IToken defaultToken) { + WordRule wordL = new WordRule(new IWordDetector() { + + @Override + public boolean isWordPart(char c) { + return !Character.isWhitespace(c); + } + + @Override + public boolean isWordStart(char c) { + return !Character.isWhitespace(c); + } + }, defaultToken); + + for (String word : words) { + wordL.addWord(word, keywordToken); + } + return wordL; + } + + // Scanners for all the various content types provided by the partitioner + private AbstractScriptScanner fCodeScanner; + private AbstractScriptScanner fCommentScanner; + private AbstractScriptScanner fDoubleQuoteScanner; + private AbstractScriptScanner fParamScanner; + private AbstractScriptScanner fEvalScanner; + private AbstractScriptScanner fHashbangScanner; + private AbstractScriptScanner fFunctionScanner; + private AbstractScriptScanner fSingleQuoteScanner; + + public ShellSourceViewerConfiguration(IColorManager colorManager, IPreferenceStore preferenceStore, + ITextEditor editor, String partitioning) { + super(colorManager, preferenceStore, editor, partitioning); + } + + @Override + public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) { + ScriptAutoIndentStrategy strategy = new ScriptAutoIndentStrategy(); + + ArrayList rules = new ArrayList<>(); + rules.add(new WhitespaceRule(new WhitespaceDetector())); + rules.add(getKeywords(new Token(IndentType.INCREMENT), new String[] { "do", "case", "{", "then" }, + Token.UNDEFINED)); + rules.add(getKeywords(new Token(IndentType.DECREMENT), new String[] { "done", "esac", "}", "fi" }, + Token.UNDEFINED)); + rules.add(getKeywords(new Token(IndentType.INFLEXION), new String[] { "else" }, Token.UNDEFINED)); + + strategy.setRules(rules.toArray(new IRule[0])); + + return new IAutoEditStrategy[] { strategy }; + } + + @Override + protected ContentAssistPreference getContentAssistPreference() { + return ShellContentAssistPreference.getDefault(); + } + + @Override + protected IInformationControlCreator getOutlinePresenterControlCreator(ISourceViewer sourceViewer, + final String commandId) { + return new IInformationControlCreator() { + @Override + public IInformationControl createInformationControl(Shell parent) { + int shellStyle = SWT.RESIZE; + int treeStyle = SWT.V_SCROLL | SWT.H_SCROLL; + return new ScriptOutlineInformationControl(parent, shellStyle, treeStyle, commandId, + Activator.getDefault().getPreferenceStore()); + } + }; + } + + @Override + public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { + PresentationReconciler reconciler = new ScriptPresentationReconciler(); + reconciler.setDocumentPartitioning(this.getConfiguredDocumentPartitioning(sourceViewer)); + + DefaultDamagerRepairer dr; + + dr = new DefaultDamagerRepairer(this.fCodeScanner); + reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); + reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); + + dr = new DefaultDamagerRepairer(this.fHashbangScanner); + reconciler.setDamager(dr, IShellPartitions.HASHBANG_CONTENT_TYPE); + reconciler.setRepairer(dr, IShellPartitions.HASHBANG_CONTENT_TYPE); + + dr = new DefaultDamagerRepairer(this.fParamScanner); + reconciler.setDamager(dr, IShellPartitions.PARAM_CONTENT_TYPE); + reconciler.setRepairer(dr, IShellPartitions.PARAM_CONTENT_TYPE); + + dr = new DefaultDamagerRepairer(this.fFunctionScanner); + reconciler.setDamager(dr, IShellPartitions.FUNCTION_CONTENT_TYPE); + reconciler.setRepairer(dr, IShellPartitions.FUNCTION_CONTENT_TYPE); + + dr = new DefaultDamagerRepairer(this.fSingleQuoteScanner); + reconciler.setDamager(dr, IShellPartitions.SINGLE_QUOTE_CONTENT_TYPE); + reconciler.setRepairer(dr, IShellPartitions.SINGLE_QUOTE_CONTENT_TYPE); + + dr = new DefaultDamagerRepairer(this.fDoubleQuoteScanner); + reconciler.setDamager(dr, IShellPartitions.DOUBLE_QUOTE_CONTENT_TYPE); + reconciler.setRepairer(dr, IShellPartitions.DOUBLE_QUOTE_CONTENT_TYPE); + + dr = new DefaultDamagerRepairer(this.fEvalScanner); + reconciler.setDamager(dr, IShellPartitions.EVAL_CONTENT_TYPE); + reconciler.setRepairer(dr, IShellPartitions.EVAL_CONTENT_TYPE); + + dr = new DefaultDamagerRepairer(this.fCommentScanner); + reconciler.setDamager(dr, IShellPartitions.COMMENT_CONTENT_TYPE); + reconciler.setRepairer(dr, IShellPartitions.COMMENT_CONTENT_TYPE); + + return reconciler; + } + + // This method called from base class. + @Override + protected void initializeScanners() { + // This is our code scanner + this.fCodeScanner = new ShellCodeScanner(this.getColorManager(), this.fPreferenceStore); + // This is default scanners for partitions with same color. + this.fFunctionScanner = new SingleTokenScriptScanner(this.getColorManager(), this.fPreferenceStore, + IShellColorConstants.SHELL_FUNCTION); + this.fHashbangScanner = new SingleTokenScriptScanner(this.getColorManager(), this.fPreferenceStore, + IShellColorConstants.SHELL_HASHBANG); + this.fSingleQuoteScanner = new SingleTokenScriptScanner(this.getColorManager(), this.fPreferenceStore, + IShellColorConstants.SHELL_SINGLE_QUOTE); + this.fDoubleQuoteScanner = new DoubleQuoteScanner(this.getColorManager(), this.fPreferenceStore); + this.fParamScanner = new SingleTokenScriptScanner(this.getColorManager(), this.fPreferenceStore, + IShellColorConstants.SHELL_VARIABLE); + this.fEvalScanner = new EvalScanner(this.getColorManager(), this.fPreferenceStore); + this.fCommentScanner = createCommentScanner(IShellColorConstants.SHELL_COMMENT, + IShellColorConstants.SHELL_TODO_TAG); + } + + @Override + protected void alterContentAssistant(ContentAssistant assistant) { + IContentAssistProcessor scriptProcessor = new ShellCompletionProcessor(getEditor(), assistant, + IDocument.DEFAULT_CONTENT_TYPE); + assistant.setContentAssistProcessor(scriptProcessor, IDocument.DEFAULT_CONTENT_TYPE); + } + + @Override + public boolean affectsTextPresentation(PropertyChangeEvent event) { + return fCodeScanner.affectsBehavior(event) || fCommentScanner.affectsBehavior(event) + || fDoubleQuoteScanner.affectsBehavior(event) || fSingleQuoteScanner.affectsBehavior(event) + || fFunctionScanner.affectsBehavior(event) || fParamScanner.affectsBehavior(event) + || fEvalScanner.affectsBehavior(event) || fHashbangScanner.affectsBehavior(event); + } + + @Override + public void handlePropertyChangeEvent(PropertyChangeEvent event) { + if (fCodeScanner.affectsBehavior(event)) { + fCodeScanner.adaptToPreferenceChange(event); + } + if (fCommentScanner.affectsBehavior(event)) { + fCommentScanner.adaptToPreferenceChange(event); + } + if (fDoubleQuoteScanner.affectsBehavior(event)) { + fDoubleQuoteScanner.adaptToPreferenceChange(event); + } + if (fSingleQuoteScanner.affectsBehavior(event)) { + fSingleQuoteScanner.adaptToPreferenceChange(event); + } + if (fFunctionScanner.affectsBehavior(event)) { + fFunctionScanner.adaptToPreferenceChange(event); + } + if (fParamScanner.affectsBehavior(event)) { + fParamScanner.adaptToPreferenceChange(event); + } + if (fEvalScanner.affectsBehavior(event)) { + fEvalScanner.adaptToPreferenceChange(event); + } + if (fHashbangScanner.affectsBehavior(event)) { + fHashbangScanner.adaptToPreferenceChange(event); + } + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/AddShellScriptInterpreterDialog.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/AddShellScriptInterpreterDialog.java new file mode 100644 index 0000000..118eb93 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/AddShellScriptInterpreterDialog.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.interpreter; + +import org.eclipse.dltk.internal.debug.ui.interpreters.AbstractInterpreterLibraryBlock; +import org.eclipse.dltk.internal.debug.ui.interpreters.AddScriptInterpreterDialog; +import org.eclipse.dltk.internal.debug.ui.interpreters.IAddInterpreterDialogRequestor; +import org.eclipse.dltk.launching.IInterpreterInstall; +import org.eclipse.dltk.launching.IInterpreterInstallType; +import org.eclipse.swt.widgets.Shell; + +public class AddShellScriptInterpreterDialog extends AddScriptInterpreterDialog { + public AddShellScriptInterpreterDialog(IAddInterpreterDialogRequestor requestor, Shell shell, + IInterpreterInstallType[] interpreterInstallTypes, IInterpreterInstall editedInterpreter) { + super(requestor, shell, interpreterInstallTypes, editedInterpreter); + } + + @Override + protected AbstractInterpreterLibraryBlock createLibraryBlock(AddScriptInterpreterDialog dialog) { + return new ShellScriptInterpreterLibraryBlock(dialog); + } +} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellInterpreterPreferencePage.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellInterpreterPreferencePage.java new file mode 100644 index 0000000..3b13bcd --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellInterpreterPreferencePage.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.interpreter; + +import org.eclipse.dltk.internal.debug.ui.interpreters.InterpretersBlock; +import org.eclipse.dltk.internal.debug.ui.interpreters.ScriptInterpreterPreferencePage; + +public class ShellInterpreterPreferencePage extends ScriptInterpreterPreferencePage { + + public static final String PAGE_ID = "org.eclipse.dltk.sh.ui.preferences.interpreters"; + + @Override + public InterpretersBlock createInterpretersBlock() { + return new ShellScriptInterpretersBlock(); + } +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellMainLaunchConfigurationTab.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellMainLaunchConfigurationTab.java new file mode 100644 index 0000000..05d7e29 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellMainLaunchConfigurationTab.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.interpreter; + +import org.eclipse.dltk.core.PreferencesLookupDelegate; +import org.eclipse.dltk.debug.ui.launchConfigurations.MainLaunchConfigurationTab; +import org.eclipse.dltk.sh.core.ShelledNature; + +public class ShellMainLaunchConfigurationTab extends MainLaunchConfigurationTab { + + public ShellMainLaunchConfigurationTab(String mode) { + super(mode); + } + + @Override + protected boolean breakOnFirstLinePrefEnabled(PreferencesLookupDelegate delegate) { + return false; + } + + @Override + protected boolean dbpgLoggingPrefEnabled(PreferencesLookupDelegate delegate) { + return false; + } + + @Override + public String getNatureID() { + return ShelledNature.SHELLED_NATURE; + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellScriptInstall.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellScriptInstall.java new file mode 100644 index 0000000..42aab8f --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellScriptInstall.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.interpreter; + +import org.eclipse.dltk.internal.launching.StandardInterpreterRunner; +import org.eclipse.dltk.launching.AbstractInterpreterInstall; +import org.eclipse.dltk.launching.IInterpreterInstallType; +import org.eclipse.dltk.launching.IInterpreterRunner; +import org.eclipse.dltk.sh.core.ShelledNature; + +public class ShellScriptInstall extends AbstractInterpreterInstall { + public ShellScriptInstall(IInterpreterInstallType type, String id) { + super(type, id); + } + + @Override + public String getNatureId() { + return ShelledNature.SHELLED_NATURE; + } + + @Override + public IInterpreterRunner getInterpreterRunner(String mode) { + return new StandardInterpreterRunner(this); + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellScriptInstallType.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellScriptInstallType.java new file mode 100644 index 0000000..a88fcb3 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellScriptInstallType.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.interpreter; + +import org.eclipse.core.runtime.ILog; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.dltk.core.environment.IDeployment; +import org.eclipse.dltk.core.environment.IFileHandle; +import org.eclipse.dltk.internal.launching.AbstractInterpreterInstallType; +import org.eclipse.dltk.launching.EnvironmentVariable; +import org.eclipse.dltk.launching.IInterpreterInstall; +import org.eclipse.dltk.launching.LibraryLocation; +import org.eclipse.dltk.sh.core.ShelledNature; +import org.eclipse.dltk.sh.internal.ui.Activator; + +public class ShellScriptInstallType extends AbstractInterpreterInstallType { + private static final String[] INTERPRETER_NAMES = { "sh", "bash", "zsh", "dash", "ksh", "tcsh", "csh" }; + + @Override + protected IPath createPathFile(IDeployment deployment) { + return null; + } + + @Override + public synchronized LibraryLocation[] getDefaultLibraryLocations(IFileHandle installLocation, + EnvironmentVariable[] variables, IProgressMonitor monitor) { + return new LibraryLocation[0]; + } + + @Override + protected IInterpreterInstall doCreateInterpreterInstall(String id) { + return new ShellScriptInstall(this, id); + } + + @Override + protected ILog getLog() { + return Activator.getDefault().getLog(); + } + + @Override + public String getName() { + return "Shell Interpreter"; + } + + @Override + public String getNatureId() { + return ShelledNature.SHELLED_NATURE; + } + + @Override + protected String getPluginId() { + return Activator.PLUGIN_ID; + } + + @Override + protected String[] getPossibleInterpreterNames() { + return INTERPRETER_NAMES; + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellScriptInterpreterLibraryBlock.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellScriptInterpreterLibraryBlock.java new file mode 100644 index 0000000..cda502e --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellScriptInterpreterLibraryBlock.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.interpreter; + +import org.eclipse.dltk.internal.debug.ui.interpreters.AbstractInterpreterLibraryBlock; +import org.eclipse.dltk.internal.debug.ui.interpreters.AddScriptInterpreterDialog; +import org.eclipse.dltk.internal.debug.ui.interpreters.LibraryLabelProvider; +import org.eclipse.jface.viewers.IBaseLabelProvider; + +public class ShellScriptInterpreterLibraryBlock extends AbstractInterpreterLibraryBlock { + public ShellScriptInterpreterLibraryBlock(AddScriptInterpreterDialog d) { + super(d); + } + + @Override + protected IBaseLabelProvider getLabelProvider() { + return new LibraryLabelProvider(); + } +} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellScriptInterpretersBlock.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellScriptInterpretersBlock.java new file mode 100644 index 0000000..5170f86 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellScriptInterpretersBlock.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.interpreter; + +import org.eclipse.dltk.core.environment.IEnvironment; +import org.eclipse.dltk.internal.debug.ui.interpreters.AddScriptInterpreterDialog; +import org.eclipse.dltk.internal.debug.ui.interpreters.InterpretersBlock; +import org.eclipse.dltk.launching.IInterpreterInstall; +import org.eclipse.dltk.launching.ScriptRuntime; +import org.eclipse.dltk.sh.core.ShelledNature; + +public class ShellScriptInterpretersBlock extends InterpretersBlock { + @Override + protected AddScriptInterpreterDialog createInterpreterDialog(IEnvironment environment, + IInterpreterInstall standin) { + AddShellScriptInterpreterDialog dialog = new AddShellScriptInterpreterDialog(this, getShell(), + ScriptRuntime.getInterpreterInstallTypes(getCurrentNature()), standin); + dialog.setEnvironment(environment); + return dialog; + } + + @Override + protected String getCurrentNature() { + return ShelledNature.SHELLED_NATURE; + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellTabGroup.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellTabGroup.java new file mode 100644 index 0000000..08ccec8 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/interpreter/ShellTabGroup.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.interpreter; + +import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup; +import org.eclipse.debug.ui.ILaunchConfigurationDialog; +import org.eclipse.debug.ui.ILaunchConfigurationTab; +import org.eclipse.dltk.debug.ui.launchConfigurations.MainLaunchConfigurationTab; +import org.eclipse.dltk.debug.ui.launchConfigurations.ScriptArgumentsTab; +import org.eclipse.dltk.debug.ui.launchConfigurations.ScriptCommonTab; + +public class ShellTabGroup extends AbstractLaunchConfigurationTabGroup { + @Override + public void createTabs(ILaunchConfigurationDialog dialog, String mode) { + MainLaunchConfigurationTab main = new ShellMainLaunchConfigurationTab(mode); + ScriptArgumentsTab args = new ScriptArgumentsTab(); + ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { main, args, new ScriptCommonTab(main) }; + setTabs(tabs); + } +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/PreviewFile.txt b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/PreviewFile.txt new file mode 100644 index 0000000..7d36825 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/PreviewFile.txt @@ -0,0 +1,7 @@ +#!/bin/sh + +if [ -z $VARIABLE ] ; then + echo "double quoted text" # some comment + echo 'single quoted text' # TODO tag + echo `command substitution` +fi \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/ShellColoringConfigurationBlock.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/ShellColoringConfigurationBlock.java new file mode 100644 index 0000000..58c3415 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/ShellColoringConfigurationBlock.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.preferences; + +import java.io.InputStream; + +import org.eclipse.dltk.internal.ui.editor.ScriptSourceViewer; +import org.eclipse.dltk.sh.internal.ui.Activator; +import org.eclipse.dltk.sh.internal.ui.IShellColorConstants; +import org.eclipse.dltk.sh.internal.ui.editor.ShellDocumentSetupParticipant; +import org.eclipse.dltk.sh.internal.ui.text.IShellPartitions; +import org.eclipse.dltk.ui.preferences.AbstractScriptEditorColoringConfigurationBlock; +import org.eclipse.dltk.ui.preferences.OverlayPreferenceStore; +import org.eclipse.dltk.ui.text.IColorManager; +import org.eclipse.dltk.ui.text.ScriptSourceViewerConfiguration; +import org.eclipse.dltk.ui.text.ScriptTextTools; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.source.IOverviewRuler; +import org.eclipse.jface.text.source.IVerticalRuler; +import org.eclipse.jface.text.source.projection.ProjectionViewer; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.texteditor.ITextEditor; + +public class ShellColoringConfigurationBlock extends AbstractScriptEditorColoringConfigurationBlock { + + private static final String PREVIEW_FILE_NAME = "PreviewFile.txt"; //$NON-NLS-1$ + + private static final String[][] fSyntaxColorListModel = new String[][] { + { "Comments", IShellColorConstants.SHELL_COMMENT, sCommentsCategory }, + { "Hashbang", IShellColorConstants.SHELL_HASHBANG, sCommentsCategory }, + { "TODO tags", IShellColorConstants.SHELL_TODO_TAG, sCommentsCategory }, + + { "Eval", IShellColorConstants.SHELL_EVAL, sCoreCategory }, + { "Double quoted text", IShellColorConstants.SHELL_DOUBLE_QUOTE, sCoreCategory }, + { "Function", IShellColorConstants.SHELL_FUNCTION, sCoreCategory }, + + { "Keyword", IShellColorConstants.SHELL_KEYWORD, sCoreCategory }, + + { "Single quoted text", IShellColorConstants.SHELL_SINGLE_QUOTE, sCoreCategory }, + { "Variables", IShellColorConstants.SHELL_VARIABLE, sCoreCategory }, + { "Commands", IShellColorConstants.SHELL_COMMAND, sCoreCategory }, + { "Default", IShellColorConstants.SHELL_DEFAULT, sCoreCategory } + + }; + + public ShellColoringConfigurationBlock(OverlayPreferenceStore store) { + super(store); + } + + @Override + protected String[][] getSyntaxColorListModel() { + return fSyntaxColorListModel; + } + + @Override + protected ProjectionViewer createPreviewViewer(Composite parent, IVerticalRuler verticalRuler, + IOverviewRuler overviewRuler, boolean showAnnotationsOverview, int styles, IPreferenceStore store) { + return new ScriptSourceViewer(parent, verticalRuler, overviewRuler, showAnnotationsOverview, styles, store); + } + + @Override + protected ScriptSourceViewerConfiguration createSimpleSourceViewerConfiguration(IColorManager colorManager, + IPreferenceStore preferenceStore, ITextEditor editor, boolean configureFormatter) { + return new SimpleShellSourceViewerConfiguration(colorManager, preferenceStore, editor, + IShellPartitions.SHELL_PARTITIONING, true); + } + + @Override + protected void setDocumentPartitioning(IDocument document) { + ShellDocumentSetupParticipant participant = new ShellDocumentSetupParticipant(); + participant.setup(document); + } + + @Override + protected InputStream getPreviewContentReader() { + return getClass().getResourceAsStream(PREVIEW_FILE_NAME); + } + + @Override + protected ScriptTextTools getTextTools() { + return Activator.getDefault().getTextTools(); + } +} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/ShellEditorPreferencesPage.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/ShellEditorPreferencesPage.java new file mode 100644 index 0000000..98bd057 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/ShellEditorPreferencesPage.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.preferences; + +import org.eclipse.dltk.sh.internal.ui.Activator; +import org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPreferencePage; +import org.eclipse.dltk.ui.preferences.EditorConfigurationBlock; +import org.eclipse.dltk.ui.preferences.IPreferenceConfigurationBlock; +import org.eclipse.dltk.ui.preferences.OverlayPreferenceStore; + +public class ShellEditorPreferencesPage extends AbstractConfigurationBlockPreferencePage { + + @Override + protected String getHelpId() { + return null; + } + + @Override + protected void setDescription() { + setDescription("Shell Script Editor preferences"); + } + + @Override + protected void setPreferenceStore() { + setPreferenceStore(Activator.getDefault().getPreferenceStore()); + } + + @Override + protected IPreferenceConfigurationBlock createConfigurationBlock(OverlayPreferenceStore overlayPreferenceStore) { + return new EditorConfigurationBlock(this, overlayPreferenceStore); + } +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/ShellFoldingPreferencePage.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/ShellFoldingPreferencePage.java new file mode 100644 index 0000000..676568d --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/ShellFoldingPreferencePage.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2014 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Peter Palaga - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.preferences; + +import org.eclipse.dltk.sh.internal.ui.Activator; +import org.eclipse.dltk.sh.internal.ui.text.folding.ShellCodeFoldingPreferenceBlock; +import org.eclipse.dltk.sh.internal.ui.text.folding.ShellCommentFoldingPreferenceBlock; +import org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPreferencePage; +import org.eclipse.dltk.ui.preferences.IPreferenceConfigurationBlock; +import org.eclipse.dltk.ui.preferences.OverlayPreferenceStore; +import org.eclipse.dltk.ui.text.folding.DefaultFoldingPreferenceConfigurationBlock; +import org.eclipse.dltk.ui.text.folding.IFoldingPreferenceBlock; +import org.eclipse.jface.preference.PreferencePage; + +/** + * A couple of usual folding options. + */ +public class ShellFoldingPreferencePage extends AbstractConfigurationBlockPreferencePage { + @Override + protected String getHelpId() { + return null; + } + + @Override + protected void setDescription() { + } + + @Override + protected void setPreferenceStore() { + setPreferenceStore(Activator.getDefault().getPreferenceStore()); + } + + @Override + protected IPreferenceConfigurationBlock createConfigurationBlock(OverlayPreferenceStore overlayPreferenceStore) { + return new DefaultFoldingPreferenceConfigurationBlock(overlayPreferenceStore, this) { + @Override + protected IFoldingPreferenceBlock createDocumentationBlock(OverlayPreferenceStore store, + PreferencePage page) { + return new ShellCommentFoldingPreferenceBlock(store, page); + } + + @Override + protected IFoldingPreferenceBlock createSourceCodeBlock(OverlayPreferenceStore store, PreferencePage page) { + return new ShellCodeFoldingPreferenceBlock(store, page); + } + }; + } +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/ShellSyntaxColoringPreferencePage.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/ShellSyntaxColoringPreferencePage.java new file mode 100644 index 0000000..0f2eea4 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/ShellSyntaxColoringPreferencePage.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.preferences; + +import org.eclipse.dltk.sh.internal.ui.Activator; +import org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPreferencePage; +import org.eclipse.dltk.ui.preferences.IPreferenceConfigurationBlock; +import org.eclipse.dltk.ui.preferences.OverlayPreferenceStore; + +public class ShellSyntaxColoringPreferencePage extends AbstractConfigurationBlockPreferencePage { + + @Override + protected String getHelpId() { + return null; + } + + @Override + protected void setDescription() { + // leave blank + } + + @Override + protected void setPreferenceStore() { + setPreferenceStore(Activator.getDefault().getPreferenceStore()); + } + + @Override + protected IPreferenceConfigurationBlock createConfigurationBlock(OverlayPreferenceStore overlayPreferenceStore) { + return new ShellColoringConfigurationBlock(overlayPreferenceStore); + } +} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/ShellTodoTaskPreferencePage.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/ShellTodoTaskPreferencePage.java new file mode 100644 index 0000000..47e1754 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/ShellTodoTaskPreferencePage.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.preferences; + +import org.eclipse.core.resources.IProject; +import org.eclipse.dltk.sh.core.ShelledNature; +import org.eclipse.dltk.sh.internal.ui.Activator; +import org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage; +import org.eclipse.dltk.ui.preferences.AbstractOptionsBlock; +import org.eclipse.dltk.ui.preferences.TodoTaskOptionsBlock; +import org.eclipse.dltk.ui.util.IStatusChangeListener; +import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; + +public class ShellTodoTaskPreferencePage extends AbstractConfigurationBlockPropertyAndPreferencePage { + + @Override + protected String getHelpId() { + return null; + } + + @Override + protected void setDescription() { + setDescription("Strings indicating tasks in Shell Script comments."); + } + + @Override + protected AbstractOptionsBlock createOptionsBlock(IStatusChangeListener newStatusChangedListener, IProject project, + IWorkbenchPreferenceContainer container) { + return new TodoTaskOptionsBlock(newStatusChangedListener, project, container, Activator.PLUGIN_ID); + } + + @Override + protected String getNatureId() { + return ShelledNature.SHELLED_NATURE; + } + + @Override + protected String getProjectHelpId() { + return null; + } + + @Override + protected void setPreferenceStore() { + setPreferenceStore(Activator.getDefault().getPreferenceStore()); + } + + @Override + protected String getPreferencePageId() { + return "org.eclipse.dltk.sh.todo"; + } + + @Override + protected String getPropertyPageId() { + return "org.eclipse.dltk.sh.todo"; + } + +} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/SimpleShellSourceViewerConfiguration.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/SimpleShellSourceViewerConfiguration.java new file mode 100644 index 0000000..6a851cb --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/preferences/SimpleShellSourceViewerConfiguration.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.preferences; + +import org.eclipse.dltk.sh.internal.ui.editor.ShellSourceViewerConfiguration; +import org.eclipse.dltk.ui.text.IColorManager; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.IAutoEditStrategy; +import org.eclipse.jface.text.IInformationControlCreator; +import org.eclipse.jface.text.ITextHover; +import org.eclipse.jface.text.formatter.IContentFormatter; +import org.eclipse.jface.text.hyperlink.IHyperlinkDetector; +import org.eclipse.jface.text.information.IInformationPresenter; +import org.eclipse.jface.text.source.IAnnotationHover; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.ui.texteditor.ITextEditor; + +public class SimpleShellSourceViewerConfiguration extends ShellSourceViewerConfiguration { + + private final boolean changeFormatter; + + public SimpleShellSourceViewerConfiguration(IColorManager colorManager, IPreferenceStore preferenceStore, + ITextEditor editor, String partitioning, boolean changeFormatter) { + super(colorManager, preferenceStore, editor, partitioning); + this.changeFormatter = changeFormatter; + } + + @Override + public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) { + return null; + } + + @Override + public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) { + return null; + } + + @Override + public IAnnotationHover getOverviewRulerAnnotationHover(ISourceViewer sourceViewer) { + return null; + } + + @Override + public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer, String contentType) { + return null; + } + + @Override + public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) { + return null; + } + + @Override + public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) { + return null; + } + + @Override + public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) { + if (changeFormatter) { + return super.getContentFormatter(sourceViewer); + } + return null; + } + + @Override + public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) { + return null; + } + + @Override + public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) { + return null; + } + + @Override + public IInformationPresenter getOutlinePresenter(ISourceViewer sourceViewer, boolean doCodeResolve) { + return null; + } + + @Override + public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) { + return null; + } +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/search/ShelledMatchLocationParser.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/search/ShelledMatchLocationParser.java new file mode 100644 index 0000000..85933c7 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/search/ShelledMatchLocationParser.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.search; + +import org.eclipse.dltk.ast.ASTNode; +import org.eclipse.dltk.core.search.matching.MatchLocator; +import org.eclipse.dltk.core.search.matching.MatchLocatorParser; +import org.eclipse.dltk.core.search.matching.PatternLocator; + +public class ShelledMatchLocationParser extends MatchLocatorParser { + protected ShelledMatchLocationParser(MatchLocator locator) { + super(locator); + } + + @Override + protected void processStatement(ASTNode node, PatternLocator locator) { + super.processStatement(node, locator); + } +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/search/ShelledSearchFactory.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/search/ShelledSearchFactory.java new file mode 100644 index 0000000..70972b1 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/search/ShelledSearchFactory.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.search; + +import org.eclipse.dltk.core.search.AbstractSearchFactory; +import org.eclipse.dltk.core.search.IMatchLocatorParser; +import org.eclipse.dltk.core.search.matching.MatchLocator; + +public class ShelledSearchFactory extends AbstractSearchFactory { + @Override + public IMatchLocatorParser createMatchParser(MatchLocator locator) { + return new ShelledMatchLocationParser(locator); + } +} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/search/ShelledSearchPage.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/search/ShelledSearchPage.java new file mode 100644 index 0000000..0c64ca9 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/search/ShelledSearchPage.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.search; + +import org.eclipse.dltk.core.IDLTKLanguageToolkit; +import org.eclipse.dltk.sh.core.ShellScriptLanguageToolkit; +import org.eclipse.dltk.ui.search.ScriptSearchPage; + +public class ShelledSearchPage extends ScriptSearchPage { + @Override + protected IDLTKLanguageToolkit getLanguageToolkit() { + return ShellScriptLanguageToolkit.getDefault(); + } +} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/selection/ShellDocumentationProvider.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/selection/ShellDocumentationProvider.java new file mode 100644 index 0000000..8269ba2 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/selection/ShellDocumentationProvider.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.selection; + +import java.io.Reader; +import java.io.StringReader; + +import org.eclipse.dltk.core.IMember; +import org.eclipse.dltk.ui.documentation.IScriptDocumentationProvider; +import org.eclipse.linuxtools.man.parser.ManPage; + +public class ShellDocumentationProvider implements IScriptDocumentationProvider { + + @Override + public Reader getInfo(String content) { + return new StringReader(new ManPage(content).getStrippedHtmlPage().toString()); + } + + @Override + public Reader getInfo(IMember element, boolean lookIntoParents, boolean lookIntoExternal) { + // TODO show comments for functions if there is any + return null; + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/selection/ShelledSelectionEngine.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/selection/ShelledSelectionEngine.java new file mode 100644 index 0000000..ef60996 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/selection/ShelledSelectionEngine.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.selection; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.dltk.ast.ASTVisitor; +import org.eclipse.dltk.ast.declarations.MethodDeclaration; +import org.eclipse.dltk.ast.declarations.ModuleDeclaration; +import org.eclipse.dltk.ast.expressions.Expression; +import org.eclipse.dltk.ast.expressions.MethodCallExpression; +import org.eclipse.dltk.ast.references.VariableReference; +import org.eclipse.dltk.codeassist.ScriptSelectionEngine; +import org.eclipse.dltk.compiler.env.IModuleSource; +import org.eclipse.dltk.core.DLTKCore; +import org.eclipse.dltk.core.IModelElement; +import org.eclipse.dltk.core.IModelElementVisitor; +import org.eclipse.dltk.core.ISourceModule; +import org.eclipse.dltk.core.ModelException; +import org.eclipse.dltk.core.SourceParserUtil; + +public class ShelledSelectionEngine extends ScriptSelectionEngine { + private ISourceModule sourceModule; + + @Override + public IModelElement[] select(IModuleSource module, final int offset, int i) { + sourceModule = (ISourceModule) module.getModelElement(); + ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(sourceModule, null); + final List results = new ArrayList<>(); + try { + moduleDeclaration.traverse(new ASTVisitor() { + @Override + public boolean visit(Expression s) throws Exception { + if ((s.sourceStart() <= offset) && (offset <= s.sourceEnd())) { + if (s instanceof MethodCallExpression) { + findDeclaration(((MethodCallExpression) s).getName(), results); + } + if (s instanceof VariableReference) { + findDeclaration(((VariableReference) s).getName(), results); + } + } + return super.visit(s); + } + + @Override + public boolean visit(MethodDeclaration s) throws Exception { + if ((s.getNameStart() <= offset) && (offset <= s.getNameEnd())) { + findDeclaration(s.getName(), results); + } + return super.visit(s); + } + + }); + } catch (Exception e) { + if (DLTKCore.DEBUG) { + e.printStackTrace(); + } + } + return results.toArray(new IModelElement[results.size()]); + } + + private void findDeclaration(final String name, final List results) { + try { + this.sourceModule.accept(new IModelElementVisitor() { + @Override + public boolean visit(IModelElement element) { + if (element.getElementName().equals(name)) { + results.add(element); + } + return true; + } + }); + } catch (ModelException e) { + if (DLTKCore.DEBUG) { + e.printStackTrace(); + } + } + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/AssignmentDetector.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/AssignmentDetector.java new file mode 100644 index 0000000..5b251b2 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/AssignmentDetector.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2011 Mat Booth and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Mat Booth + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text; + +import org.eclipse.jface.text.rules.IWordDetector; + +/** + * Determines whether given any given character forms part of a shell + * assignment. + */ +public class AssignmentDetector implements IWordDetector { + + @Override + public boolean isWordPart(char c) { + return Character.isJavaIdentifierPart(c) || (c == '[') || (c == ']'); + } + + @Override + public boolean isWordStart(char c) { + return Character.isJavaIdentifierStart(c); + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/AssignmentRule.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/AssignmentRule.java new file mode 100644 index 0000000..51a0d86 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/AssignmentRule.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text; + +import org.eclipse.jface.text.rules.ICharacterScanner; +import org.eclipse.jface.text.rules.IRule; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.IWordDetector; +import org.eclipse.jface.text.rules.Token; + +public class AssignmentRule implements IRule { + private final StringBuffer buffer = new StringBuffer(); + private final IToken defaultToken; + private final IWordDetector detector; + private final IToken successToken; + + public AssignmentRule(IWordDetector detector, IToken defaultToken, IToken token) { + this.detector = detector; + this.successToken = token; + this.defaultToken = defaultToken; + } + + @Override + public IToken evaluate(ICharacterScanner scanner) { + char c = (char) scanner.read(); + if (detector.isWordStart((c))) { + buffer.setLength(0); + do { + buffer.append((c)); + c = (char) scanner.read(); + } while ((c != ICharacterScanner.EOF) && detector.isWordPart(c)); + scanner.unread(); + if (c == '=') { + return successToken; + } + if (defaultToken.isUndefined()) { + unreadBuffer(scanner); + } + return defaultToken; + } + scanner.unread(); + return Token.UNDEFINED; + } + + /** + * Returns the characters in the buffer to the scanner. + * + * @param scanner + * the scanner to be used + */ + protected void unreadBuffer(ICharacterScanner scanner) { + for (int i = buffer.length() - 1; i >= 0; i--) { + scanner.unread(); + } + } +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/DocumentAndCommandScanner.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/DocumentAndCommandScanner.java new file mode 100644 index 0000000..cd0db4b --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/DocumentAndCommandScanner.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.DocumentCommand; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.rules.RuleBasedScanner; + +/** + * This scanner extends the normal rule based scanner by adding the ability to + * read DocumentCommands as well as IDocuments. This ability is toggled on or + * off depending on whether setRange(document,offset,length) (off) or + * setRange(document,documentCommand,offset,length) (on) was called. + * + * @author Doug Satchwell + * @version $Id: DocumentAndCommandScanner.java,v 1.2 2008/12/02 21:59:55 + * akurtakov Exp $ + */ +public class DocumentAndCommandScanner extends RuleBasedScanner { + private DocumentCommand fDocumentCommand; + + @Override + public int read() { + try { + if (fOffset < fRangeEnd) { + try { + return fDocument.getChar(fOffset); + } catch (BadLocationException e) { + } + } + if ((fDocumentCommand != null) && (fOffset < (fRangeEnd + fDocumentCommand.text.length()))) { + return fDocumentCommand.text.charAt(((fRangeEnd + fDocumentCommand.text.length()) - fOffset) - 1); + } + return EOF; + } finally { + ++fOffset; + } + } + + /** + * Set this to use as a normal in conjunction with DocumentCommand's + */ + public void setRange(IDocument document, DocumentCommand documentCommand, int offset, int length) { + setRange(document, offset, length); + fDocumentCommand = documentCommand; + } + + /** + * Set this to use as a normal RuleBasedScanner + */ + @Override + public void setRange(IDocument document, int offset, int length) { + super.setRange(document, offset, length); + fDocumentCommand = null; + } +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/DollarBraceCountingRule.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/DollarBraceCountingRule.java new file mode 100644 index 0000000..f9adede --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/DollarBraceCountingRule.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2009 Mat Booth and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text; + +import org.eclipse.jface.text.rules.ICharacterScanner; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.PatternRule; + +/** + * This rule captures a pattern that begins with '$' and an opening brace and + * ends with a closed brace. This is used for highlighting ${} or $() blocks. It + * counts the opening and closing braces as it encounters them to make sure we + * always end at the correct closing brace or the end of the line, which ever + * comes first. + */ +public class DollarBraceCountingRule extends PatternRule { + + private char[][] fLineDelimiters; + private char[][] fSortedLineDelimiters; + + private final char fOpening; + private final char fClosing; + + /** + * Creates a rule for the given opening and closing braces. When these + * braces are detected the rule will return the specified token. + * Alternatively, the sequence can also be ended by the end of the line. Any + * character which follows the given escapeCharacter will be ignored. + * + * @param openingBrace + * the pattern's start sequence + * @param closingBrace + * the pattern's end sequence, null is a legal value + * @param token + * the token which will be returned on success + * @param escapeChar + * any character following this one will be ignored + */ + public DollarBraceCountingRule(char openingBrace, char closingBrace, IToken token, char escapeChar) { + super("$" + Character.toString(openingBrace), Character.toString(closingBrace), token, escapeChar, true, false, + false); + fOpening = openingBrace; + fClosing = closingBrace; + } + + /** + * This method is rather more or less identical to the super class + * implementation with the exception that instead of checking for the end + * sequence, it counts occurrences of braces and returns successfully when + * the number of closing braces encountered equals the number of opening + * braces. + * + * @see org.eclipse.jface.text.rules.PatternRule#endSequenceDetected(org.eclipse.jface.text.rules.ICharacterScanner) + */ + @Override + protected boolean endSequenceDetected(ICharacterScanner scanner) { + char[][] originalDelimiters = scanner.getLegalLineDelimiters(); + int count = originalDelimiters.length; + if ((fLineDelimiters == null) || (originalDelimiters.length != count)) { + fSortedLineDelimiters = new char[count][]; + } else { + while ((count > 0) && (fLineDelimiters[count - 1] == originalDelimiters[count - 1])) { + count--; + } + } + if (count != 0) { + fLineDelimiters = originalDelimiters; + System.arraycopy(fLineDelimiters, 0, fSortedLineDelimiters, 0, fLineDelimiters.length); + } + + int readCount = 1; + int c; + int fBraceCount = 1; + while ((c = scanner.read()) != ICharacterScanner.EOF) { + if (c == fEscapeCharacter) { + // Skip escaped character(s) + if (fEscapeContinuesLine) { + c = scanner.read(); + for (char[] fSortedLineDelimiter : fSortedLineDelimiters) { + if ((c == fSortedLineDelimiter[0]) && sequenceDetected(scanner, fSortedLineDelimiter, true)) { + break; + } + } + } else + scanner.read(); + + } else if (c == fOpening) { + // Count opening braces + fBraceCount++; + } else if (c == fClosing) { + // Count closing braces + fBraceCount--; + // End successfully when the open brace count returns to zero + if (fBraceCount == 0) { + return true; + } + } else if (fBreaksOnEOL) { + // Check for end of line since it can be used to terminate the + // pattern. + for (char[] fSortedLineDelimiter : fSortedLineDelimiters) { + if ((c == fSortedLineDelimiter[0]) && sequenceDetected(scanner, fSortedLineDelimiter, true)) { + return true; + } + } + } + readCount++; + } + + if (fBreaksOnEOF) { + return true; + } + + for (; readCount > 0; readCount--) { + scanner.unread(); + } + + return false; + } +} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/DollarDetector.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/DollarDetector.java new file mode 100644 index 0000000..b4835ac --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/DollarDetector.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text; + +import org.eclipse.jface.text.rules.IWordDetector; + +/** + * Determines whether given any given character forms part of a shell variable. + */ +public class DollarDetector implements IWordDetector { + + @Override + public boolean isWordPart(char c) { + return Character.isJavaIdentifierPart(c); + } + + @Override + public boolean isWordStart(char c) { + return c == '$'; + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/DollarRule.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/DollarRule.java new file mode 100644 index 0000000..74eb369 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/DollarRule.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text; + +import org.eclipse.jface.text.rules.ICharacterScanner; +import org.eclipse.jface.text.rules.IRule; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.IWordDetector; +import org.eclipse.jface.text.rules.Token; + +/** + * This rule captures parameter expansions that are not covered by + * DollarBraceCountingRule. That is, all dollar-prefixed variables including + * special variables where encapsulation in braces is not necessary. + */ +public class DollarRule implements IRule { + + private final StringBuffer buffer = new StringBuffer(); + private final IToken defaultToken; + private final IWordDetector detector; + private final IToken successToken; + + public DollarRule(IWordDetector detector, IToken defaultToken, IToken token) { + this.detector = detector; + this.successToken = token; + this.defaultToken = defaultToken; + } + + /** + * Returns whether the specified character is a special parameter in shell + * script. A dollar sign combined with any of the following characters will + * be highlighted, but no characters after that. + *

+ * '*', '@' - positional parameters starting from 1
+ * '#' - number of positional parameters
+ * '?' - exit status of the last executed foreground command
+ * '-' - current option flags
+ * '$' - PID of the shell
+ * '!' - PID of the last executed background command
+ * '_' - pathname used to invoke the shell and every subsequent command
+ * '0' - usually the name of the file used to invoke the shell
+ * '1' to '9' - expands to the corresponding positional parameters, + * parameters 10+ must be referenced with braces like ${12} + * + * @param c + * a character to test + * @return true if the specified character is a special parameter + */ + private static boolean isSpecial(char c) { + return ((c == '*') || (c == '@') || (c == '#') || (c == '?') || (c == '-') || (c == '$') || (c == '!') + || (c == '_') || Character.isDigit(c)); + } + + @Override + public IToken evaluate(ICharacterScanner scanner) { + int c = scanner.read(); + if (detector.isWordStart((char) c)) { + buffer.setLength(0); + do { + buffer.append((char) c); + c = scanner.read(); + if ((buffer.length() == 1) && isSpecial((char) c)) { + return successToken; + } + } while ((c != ICharacterScanner.EOF) && detector.isWordPart((char) c)); + scanner.unread(); + if (buffer.length() > 1) { + return successToken; + } + if (defaultToken.isUndefined()) { + unreadBuffer(scanner); + } + return defaultToken; + } + scanner.unread(); + return Token.UNDEFINED; + } + + /** + * Returns the characters in the buffer to the scanner. + * + * @param scanner + * the scanner to be used + */ + protected void unreadBuffer(ICharacterScanner scanner) { + for (int i = buffer.length() - 1; i >= 0; i--) { + scanner.unread(); + } + } +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/DoubleQuoteScanner.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/DoubleQuoteScanner.java new file mode 100644 index 0000000..b25cc35 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/DoubleQuoteScanner.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2009-2010 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.dltk.sh.internal.ui.IShellColorConstants; +import org.eclipse.dltk.ui.text.AbstractScriptScanner; +import org.eclipse.dltk.ui.text.IColorManager; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.rules.IRule; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.SingleLineRule; +import org.eclipse.jface.text.rules.WhitespaceRule; + +/** + * Scans interpolated string partitions of documents. I.e., the sections between + * double quote marks. + */ +public class DoubleQuoteScanner extends AbstractScriptScanner { + + /** + * Array of preference keys used to define the style of token types used by + * this scanner. + */ + private static String fgTokenProperties[] = new String[] { IShellColorConstants.SHELL_EVAL, + IShellColorConstants.SHELL_DOUBLE_QUOTE, IShellColorConstants.SHELL_VARIABLE }; + + public DoubleQuoteScanner(IColorManager manager, IPreferenceStore store) { + super(manager, store); + initialize(); + } + + @Override + protected List createRules() { + List rules = new ArrayList<>(); + + // Token types used in the rules + IToken defaultToken = this.getToken(IShellColorConstants.SHELL_DOUBLE_QUOTE); + IToken evalToken = this.getToken(IShellColorConstants.SHELL_EVAL); + IToken varToken = this.getToken(IShellColorConstants.SHELL_VARIABLE); + + // Add generic whitespace rule. This is here for efficiency reasons, + // there is a LOT of whitespace and when a token is detected the other + // rules are not evaluated. + rules.add(new WhitespaceRule(new WhitespaceDetector())); + rules.add(new DollarBraceCountingRule('(', ')', evalToken, '\\')); + rules.add(new DollarBraceCountingRule('{', '}', varToken, '\\')); + rules.add(new DollarRule(new DollarDetector(), defaultToken, varToken)); + rules.add(new SingleLineRule("`", "`", evalToken, '\\', false)); + setDefaultReturnToken(defaultToken); + return rules; + } + + @Override + protected String[] getTokenProperties() { + return fgTokenProperties; + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/EvalScanner.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/EvalScanner.java new file mode 100644 index 0000000..a9bce1b --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/EvalScanner.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2010 Mat Booth and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.dltk.sh.internal.ui.IShellColorConstants; +import org.eclipse.dltk.ui.text.AbstractScriptScanner; +import org.eclipse.dltk.ui.text.IColorManager; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.rules.IRule; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.WhitespaceRule; + +/** + * Scans command substitution document partitions. I.e., the sections between + * back-ticks or enclosed in $()s. + */ +public class EvalScanner extends AbstractScriptScanner { + + /** + * Array of preference keys used to define the style of token types used by + * this scanner. + */ + private static String fgTokenProperties[] = new String[] { IShellColorConstants.SHELL_EVAL, + IShellColorConstants.SHELL_VARIABLE }; + + public EvalScanner(IColorManager manager, IPreferenceStore store) { + super(manager, store); + initialize(); + } + + @Override + protected List createRules() { + List rules = new ArrayList<>(); + + // Token types used in the rules + IToken defaultToken = this.getToken(IShellColorConstants.SHELL_EVAL); + IToken varToken = this.getToken(IShellColorConstants.SHELL_VARIABLE); + + // Add generic whitespace rule. This is here for efficiency reasons, + // there is a LOT of whitespace and when a token is detected the other + // rules are not evaluated. + rules.add(new WhitespaceRule(new WhitespaceDetector())); + rules.add(new DollarBraceCountingRule('{', '}', varToken, '\\')); + rules.add(new DollarRule(new DollarDetector(), defaultToken, varToken)); + setDefaultReturnToken(defaultToken); + return rules; + } + + @Override + protected String[] getTokenProperties() { + return fgTokenProperties; + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/IShellPartitions.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/IShellPartitions.java new file mode 100644 index 0000000..0ed368f --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/IShellPartitions.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text; + +import org.eclipse.jface.text.IDocument; + +public interface IShellPartitions { + String SHELL_PARTITIONING = "__shell_partitioning"; + + // Content types supplied by the shell script partitioner + String COMMENT_CONTENT_TYPE = "__comment"; + String DOUBLE_QUOTE_CONTENT_TYPE = "__double_quote"; + String PARAM_CONTENT_TYPE = "__parameter"; + String EVAL_CONTENT_TYPE = "__eval"; + String HASHBANG_CONTENT_TYPE = "__hashbang"; + String FUNCTION_CONTENT_TYPE = "__function"; + String SINGLE_QUOTE_CONTENT_TYPE = "__single_quote"; + + String[] CONTENT_TYPES = new String[] { IDocument.DEFAULT_CONTENT_TYPE, HASHBANG_CONTENT_TYPE, COMMENT_CONTENT_TYPE, + SINGLE_QUOTE_CONTENT_TYPE, DOUBLE_QUOTE_CONTENT_TYPE, PARAM_CONTENT_TYPE, EVAL_CONTENT_TYPE, + FUNCTION_CONTENT_TYPE }; +} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/IndentType.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/IndentType.java new file mode 100644 index 0000000..c5635af --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/IndentType.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text; + +/** + * A type of indent. + */ +public final class IndentType { + /** A single indent decrement */ + public static final IndentType DECREMENT = new IndentType(); + /** A single indent increment */ + public static final IndentType INCREMENT = new IndentType(); + /** An inflexion - both an increment and a decrement */ + public static final IndentType INFLEXION = new IndentType(); + + private IndentType() { + } +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ScriptAutoIndentStrategy.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ScriptAutoIndentStrategy.java new file mode 100644 index 0000000..8398b3f --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ScriptAutoIndentStrategy.java @@ -0,0 +1,346 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + * Mat Booth + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text; + +import org.eclipse.dltk.sh.internal.ui.Activator; +import org.eclipse.dltk.ui.CodeFormatterConstants; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.DocumentCommand; +import org.eclipse.jface.text.IAutoEditStrategy; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.TextUtilities; +import org.eclipse.jface.text.rules.IRule; +import org.eclipse.jface.text.rules.IToken; + +/** + * An indent strategy capable of indenting and unindenting on any set of words, + * depending on the rules that are set. + * + * @see #setRules(IRule[]) + */ +public class ScriptAutoIndentStrategy implements IAutoEditStrategy { + /** + * Document scanner used to identify indentations. + */ + private final DocumentAndCommandScanner scanner = new DocumentAndCommandScanner(); + + /** + * Set the rules that will be used in a document scanner to identify where + * indentations should occur. Typically you'd have one rule to describe each + * type of indentation. + * + * @param rules + * the list of rules + * @see IndentType + */ + public void setRules(IRule[] rules) { + scanner.setRules(rules); + } + + /** + * This implementation attempts to auto-indent and auto-unindent after + * keywords that require it. + */ + @Override + public void customizeDocumentCommand(IDocument d, DocumentCommand c) { + int delim = TextUtilities.endsWith(d.getLegalLineDelimiters(), c.text); + if ((c.length == 0) && (c.text != null) && (delim != -1)) { + smartIndentAfterNewLine(d, c); + } else if (c.text.length() == 1) { + smartIndentAfterKeypress(d, c); + } + } + + /** + * Set the indent of a new line when the user hits carriage return. The new + * indent will either be the same as the previous line or incremented if the + * user has hit carriage return on a line that contains a incrementing + * keyword. + * + * @param document + * the document being parsed + * @param c + * the command being performed + */ + protected void smartIndentAfterNewLine(IDocument document, DocumentCommand c) { + if ((c.offset == -1) || (document.getLength() == 0)) { + return; + } + try { + StringBuffer buf = new StringBuffer(c.text); + int p = c.offset == document.getLength() ? c.offset - 1 : c.offset; + int line = document.getLineOfOffset(p); + int start = document.getLineOffset(line); + int bracketCount = getBracketCount(document, null, start, c.offset, true); + buf.append(generateIndentation(getIndentOfLine(document, line), bracketCount <= 0 ? 0 : 1)); + c.text = buf.toString(); + } catch (BadLocationException x) { + x.printStackTrace(); + } + } + + /** + * Set the indent of the current line when the user hits a key. The indent + * will either be unchanged or decremented if the user types + * + * @param document + * the document being parsed + * @param c + * the command being performed + */ + protected void smartIndentAfterKeypress(IDocument document, DocumentCommand c) { + if ((c.offset == -1) || (document.getLength() == 0)) { + return; + } + try { + StringBuffer buf = new StringBuffer(); + int p = c.offset == document.getLength() ? c.offset - 1 : c.offset; + int line = document.getLineOfOffset(p); + int start = document.getLineOffset(line); + int whiteEnd = findEndOfWhiteSpace(document, start, c.offset); + + int bracketCount = getBracketCount(document, c, start, c.offset, false); + buf.append(generateIndentation(getIndentOfLine(document, line), bracketCount >= 0 ? 0 : -1)); + buf.append(document.get(whiteEnd, c.offset - whiteEnd)); + buf.append(c.text); + // Alter the command + c.length = (c.offset - start) + c.length; + c.offset = start; + c.text = buf.toString(); + } catch (BadLocationException x) { + x.printStackTrace(); + } + } + + /** + * Returns the first offset greater than offset and smaller + * than end whose character is not a space or tab character. If + * no such offset is found, end is returned. + * + * @param document + * the document to search in + * @param offset + * the offset at which searching start + * @param end + * the offset at which searching stops + * @return the offset in the specified range whose character is not a space + * or tab + * @exception BadLocationException + * if offset is an invalid position in the given document + */ + private static int findEndOfWhiteSpace(IDocument document, int offset, int end) throws BadLocationException { + while (offset < end) { + char c = document.getChar(offset); + if ((c != ' ') && (c != '\t')) { + return offset; + } + offset++; + } + return end; + } + + /** + * Returns the indentation of the specified line in document. + * + * @param document + * - the document being parsed + * @param line + * - the line number being searched + * @return the string containing the indentation from the specified line + */ + private static String getIndentOfLine(IDocument document, int line) throws BadLocationException { + if (line > -1) { + int start = document.getLineOffset(line); + int end = start + document.getLineLength(line); + int whiteend = findEndOfWhiteSpace(document, start, end); + return document.get(start, whiteend - start); + } else { + return ""; + } + } + + /** + * Returns the bracket count of a section of text. The count is incremented + * when an opening bracket is encountered and decremented when a closing + * bracket is encountered. + * + * @param document + * - the document being parsed + * @param command + * - if not null, the inserted text specified by the command will + * be taken into account as if it were part of the document + * @param start + * - the start position for the search + * @param end + * - the end position for the search + * @param ignoreInflexions + * - whether or not to ignore inflexions in the count + * @return the resulting bracket count, a positive value means we've + * encountered more opening than closing brackets + */ + private int getBracketCount(IDocument document, DocumentCommand command, int start, int end, + boolean ignoreInflexions) { + int bracketcount = 0; + if (command != null) { + scanner.setRange(document, command, start, end - start); + } else { + scanner.setRange(document, start, end - start); + } + + while (true) { + IToken token = scanner.nextToken(); + if (token.isEOF()) { + break; + } + + if (token.isOther()) { + IndentType type = (IndentType) token.getData(); + if (type == IndentType.INCREMENT) { + ++bracketcount; + } else if (type == IndentType.DECREMENT) { + --bracketcount; + } else if ((type == IndentType.INFLEXION) && ignoreInflexions) { + ++bracketcount; + } else if ((type == IndentType.INFLEXION) && !ignoreInflexions) { + --bracketcount; + } + } + } + return bracketcount; + } + + /** + * Calculate the indentation needed for a new line based on the contents of + * the previous line. + * + * @param previous + * a string containing the indentation of the previous line + * @param additional + * number of desired addition indentations, may be negative + * @return a string containing the indentation to use on the new line + */ + private static String generateIndentation(String previous, int additional) { + // Get the indentation preferences + IPreferenceStore prefs = Activator.getDefault().getPreferenceStore(); + String tabChar = prefs.getString(CodeFormatterConstants.FORMATTER_TAB_CHAR); + int indentSize = prefs.getInt(CodeFormatterConstants.FORMATTER_INDENTATION_SIZE); + int tabSize = prefs.getInt(CodeFormatterConstants.FORMATTER_TAB_SIZE); + + // Size in characters of the indentation of the previous line + int preLength = computeVisualLength(previous, tabSize); + + // Number of addition characters needed + int addLength = indentSize * additional; + + // Target size of the indentation for the new line + int endLength = Math.max(0, preLength + addLength); + + // Trim previous indentation back to nearest tab stop + int minLength = Math.min(endLength, preLength); + int maxCopyLength = tabSize > 0 ? minLength - (minLength % tabSize) : minLength; // maximum + // indent + // to + // copy + String indent = stripExtraChars(previous, maxCopyLength, tabSize); + + // Add additional indentation + int missing = endLength - maxCopyLength; + final int tabs, spaces; + if (CodeFormatterConstants.SPACE.equals(tabChar)) { + // Each indent is a number of spaces equal to indent size + tabs = 0; + spaces = missing; + } else if (CodeFormatterConstants.TAB.equals(tabChar)) { + // Missing should always be in multiples of indent size, so this + // means "one tab per indent" and indent size is essentially ignored + tabs = missing / indentSize; + spaces = 0; + } else if (CodeFormatterConstants.MIXED.equals(tabChar)) { + // If the missing indent is a multiple of tab size then tabs will be + // used, otherwise use spaces + tabs = tabSize > 0 ? missing / tabSize : 0; + spaces = tabSize > 0 ? missing % tabSize : missing; + } else { + tabs = 0; + spaces = 0; + } + for (int i = 0; i < tabs; i++) { + indent += "\t"; + } + for (int i = 0; i < spaces; i++) { + indent += " "; + } + return indent; + } + + /** + * Computes the length of a an indentation, counting a tab character as the + * size until the next tab stop and every other character as one. + * + * @param indent + * the string containing the indentation to measure + * @param tabSize + * the visual size of tab characters + * @return the visual length in number of characters + */ + private static int computeVisualLength(String indent, int tabSize) { + int length = 0; + for (int i = 0; i < indent.length(); i++) { + char ch = indent.charAt(i); + switch (ch) { + case '\t': + if (tabSize > 0) { + int reminder = length % tabSize; + length += tabSize - reminder; + } + break; + case ' ': + length++; + break; + } + } + return length; + } + + /** + * Strips any characters off the end of an indentation that exceed a + * specified maximum visual indentation length. + * + * @param indent + * the string containing the indentation to measure + * @param max + * the maximum visual indentation length + * @param tabSize + * the visual size of tab characters + * @return a string containing the stripped indentation + */ + private static String stripExtraChars(String indent, int max, int tabSize) { + int measured = 0; + int i = 0; + for (; (measured < max) && (i < indent.length()); i++) { + char ch = indent.charAt(i); + switch (ch) { + case '\t': + if (tabSize > 0) { + int reminder = measured % tabSize; + measured += tabSize - reminder; + } + break; + case ' ': + measured++; + break; + } + } + return indent.substring(0, measured > max ? i - 1 : i); + } +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ShellCodeScanner.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ShellCodeScanner.java new file mode 100644 index 0000000..80a8547 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ShellCodeScanner.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * Copyright (c) 2009-2011 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + * Mat Booth + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.dltk.sh.internal.ui.Activator; +import org.eclipse.dltk.sh.internal.ui.IShellColorConstants; +import org.eclipse.dltk.ui.text.AbstractScriptScanner; +import org.eclipse.dltk.ui.text.IColorManager; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.rules.IRule; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.IWordDetector; +import org.eclipse.jface.text.rules.Token; +import org.eclipse.jface.text.rules.WhitespaceRule; +import org.eclipse.jface.text.rules.WordRule; + +public class ShellCodeScanner extends AbstractScriptScanner { + public static class ShellWordDetector implements IWordDetector { + @Override + public boolean isWordPart(char character) { + return (Character.isJavaIdentifierPart(character) && (character != '$')) || (character == '-') + || (character == '.'); + } + + @Override + public boolean isWordStart(char character) { + return Character.isJavaIdentifierStart(character) && (character != 36); + } + } + + public static final String[] KEYWORDS = { "do", "done", "if", "fi", "then", "else", "elif", "case", "esac", "while", + "for", "in", "select", "time", "until", "function", "[", "[[", "]", "]]", "set", "unset", "declare" }; + + private static List fgCommands = getCommands(); + + private static String fgTokenProperties[] = new String[] { IShellColorConstants.SHELL_DEFAULT, + IShellColorConstants.SHELL_KEYWORD, IShellColorConstants.SHELL_VARIABLE, + IShellColorConstants.SHELL_COMMAND }; + + public ShellCodeScanner(IColorManager manager, IPreferenceStore store) { + super(manager, store); + this.initialize(); + } + + public static List getCommands() { + String path = System.getenv("PATH"); + List commands = new ArrayList<>(); + String[] pathEntries = path.split(System.getProperty("path.separator")); + for (String pathEntry : pathEntries) { + File dir = new File(pathEntry); + if (dir.exists() && dir.isDirectory()) { + + File[] files = dir.listFiles(); + + // GRO: Prevent NullPointerException + if (files == null) { + // @formatter:off + Activator.getDefault().getLog().log(// + + new Status(IStatus.ERROR, Activator.PLUGIN_ID, "listFiles() returned null: " + dir)); + // @formatter:on + files = new File[] {}; + } + + for (File file : files) { + if (file.canExecute()) { + if (file.getName().endsWith(".exe")) { + commands.add(file.getName().substring(0, file.getName().length() - 4)); + } else { + commands.add(file.getName()); + } + } + } + } + } + return commands; + } + + @Override + protected List createRules() { + List rules = new ArrayList<>(); + IToken keyword = this.getToken(IShellColorConstants.SHELL_KEYWORD); + IToken commandToken = this.getToken(IShellColorConstants.SHELL_COMMAND); + IToken other = this.getToken(IShellColorConstants.SHELL_DEFAULT); + IToken variable = this.getToken(IShellColorConstants.SHELL_VARIABLE); + rules.add(new WhitespaceRule(new WhitespaceDetector())); + rules.add(new AssignmentRule(new AssignmentDetector(), Token.UNDEFINED, variable)); + rules.add(new DollarRule(new DollarDetector(), Token.UNDEFINED, variable)); + WordRule wordRule = new WordRule(new ShellWordDetector(), other); + for (String element : KEYWORDS) { + wordRule.addWord(element, keyword); + } + for (String command : fgCommands) { + wordRule.addWord(command, commandToken); + } + rules.add(wordRule); + return rules; + } + + @Override + protected String[] getTokenProperties() { + return fgTokenProperties; + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ShellPartitionScanner.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ShellPartitionScanner.java new file mode 100644 index 0000000..6690671 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ShellPartitionScanner.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ + +package org.eclipse.dltk.sh.internal.ui.text; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.text.rules.EndOfLineRule; +import org.eclipse.jface.text.rules.IPredicateRule; +import org.eclipse.jface.text.rules.IRule; +import org.eclipse.jface.text.rules.RuleBasedPartitionScanner; +import org.eclipse.jface.text.rules.SingleLineRule; +import org.eclipse.jface.text.rules.Token; + +public class ShellPartitionScanner extends RuleBasedPartitionScanner { + + public ShellPartitionScanner() { + super(); + + List rules = new ArrayList<>(); + // Add rule for single line comments. + rules.add(new EndOfLineRule("#!", new Token(IShellPartitions.HASHBANG_CONTENT_TYPE))); + /* + * There are 2 comment rules in order to correctly support # in + * variables. + */ + // This rule recognizes only comments starting from the beginning of + // line. + EndOfLineRule commentRule = new EndOfLineRule("#", new Token(IShellPartitions.COMMENT_CONTENT_TYPE)); + commentRule.setColumnConstraint(0); + rules.add(commentRule); + // This rule recognizes only comments which has space in front of it + commentRule = new EndOfLineRule(" #", new Token(IShellPartitions.COMMENT_CONTENT_TYPE)); + rules.add(commentRule); + commentRule = new EndOfLineRule("\t#", new Token(IShellPartitions.COMMENT_CONTENT_TYPE)); + rules.add(commentRule); + + rules.add(new DollarBraceCountingRule('(', ')', new Token(IShellPartitions.EVAL_CONTENT_TYPE), '\\')); + rules.add(new DollarBraceCountingRule('{', '}', new Token(IShellPartitions.PARAM_CONTENT_TYPE), '\\')); + rules.add(new SingleLineRule("`", "`", new Token(IShellPartitions.EVAL_CONTENT_TYPE), '\\', false, true)); + rules.add(new SingleLineRule("\"", "\"", new Token(IShellPartitions.DOUBLE_QUOTE_CONTENT_TYPE), '\\', false, + true)); + rules.add( + new SingleLineRule("'", "'", new Token(IShellPartitions.SINGLE_QUOTE_CONTENT_TYPE), '\\', false, true)); + + IPredicateRule[] result = new IPredicateRule[rules.size()]; + rules.toArray(result); + setPredicateRules(result); + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ShellTextTools.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ShellTextTools.java new file mode 100644 index 0000000..9672d1b --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ShellTextTools.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text; + +import org.eclipse.dltk.sh.internal.ui.editor.ShellSourceViewerConfiguration; +import org.eclipse.dltk.ui.text.ScriptSourceViewerConfiguration; +import org.eclipse.dltk.ui.text.ScriptTextTools; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.rules.IPartitionTokenScanner; +import org.eclipse.ui.texteditor.ITextEditor; + +public class ShellTextTools extends ScriptTextTools { + + private final IPartitionTokenScanner fPartitionScanner; + + public ShellTextTools(boolean autoDisposeOnDisplayDispose) { + super(IShellPartitions.SHELL_PARTITIONING, IShellPartitions.CONTENT_TYPES, autoDisposeOnDisplayDispose); + fPartitionScanner = new ShellPartitionScanner(); + } + + @Override + public ScriptSourceViewerConfiguration createSourceViewerConfiguraton(IPreferenceStore preferenceStore, + ITextEditor editor, String partitioning) { + return new ShellSourceViewerConfiguration(getColorManager(), preferenceStore, editor, partitioning); + } + + @Override + public IPartitionTokenScanner createPartitionScanner() { + return fPartitionScanner; + } + +} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/WhitespaceDetector.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/WhitespaceDetector.java new file mode 100644 index 0000000..4f5ee07 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/WhitespaceDetector.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text; + +import org.eclipse.jface.text.rules.IWhitespaceDetector; + +public class WhitespaceDetector implements IWhitespaceDetector { + + @Override + public boolean isWhitespace(char c) { + return Character.isWhitespace(c); + } +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/folding/FoldingBlockKind.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/folding/FoldingBlockKind.java new file mode 100644 index 0000000..734a724 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/folding/FoldingBlockKind.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text.folding; + +import org.eclipse.dltk.ui.text.folding.IFoldingBlockKind; + +public enum FoldingBlockKind implements IFoldingBlockKind { + FUNCTION, COMMENT; + + @Override + public boolean isComment() { + return this == COMMENT; + } +} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/folding/ShellCodeFoldingBlockProvider.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/folding/ShellCodeFoldingBlockProvider.java new file mode 100644 index 0000000..ba9f1af --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/folding/ShellCodeFoldingBlockProvider.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text.folding; + +import org.eclipse.dltk.core.IMethod; +import org.eclipse.dltk.core.IModelElement; +import org.eclipse.dltk.ui.PreferenceConstants; +import org.eclipse.dltk.ui.text.folding.IFoldingBlockKind; +import org.eclipse.dltk.ui.text.folding.ModelFoldingBlockProvider; +import org.eclipse.jface.preference.IPreferenceStore; + +public class ShellCodeFoldingBlockProvider extends ModelFoldingBlockProvider { + private int minimalLineCount; + private boolean foldingEnabled; + private boolean functionsCollapsedInitially; + + @Override + public boolean visit(IModelElement element) { + if (element instanceof IMethod) { + reportElement(element); + } + return true; + } + + @Override + public void initializePreferences(IPreferenceStore preferenceStore) { + super.initializePreferences(preferenceStore); + minimalLineCount = preferenceStore.getInt(PreferenceConstants.EDITOR_FOLDING_LINES_LIMIT); + foldingEnabled = preferenceStore.getBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED); + functionsCollapsedInitially = preferenceStore.getBoolean(PreferenceConstants.EDITOR_FOLDING_INIT_METHODS); + } + + @Override + public int getMinimalLineCount() { + return minimalLineCount; + } + + @Override + protected boolean isFoldedInitially(IModelElement element) { + if (foldingEnabled) { + if (element instanceof IMethod) { + return functionsCollapsedInitially; + } + } + return false; + } + + @Override + protected IFoldingBlockKind getKind(IModelElement element) { + if (element instanceof IMethod) { + return FoldingBlockKind.FUNCTION; + } + /* + * this should not happen. getKind() should be called for functions only + * because we reportElement() only for IMethod in visit() + */ + return null; + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/folding/ShellCodeFoldingPreferenceBlock.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/folding/ShellCodeFoldingPreferenceBlock.java new file mode 100644 index 0000000..254dcce --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/folding/ShellCodeFoldingPreferenceBlock.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2014 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Peter Palaga - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text.folding; + +import org.eclipse.dltk.ui.preferences.OverlayPreferenceStore; +import org.eclipse.dltk.ui.text.folding.SourceCodeFoldingPreferenceBlock; +import org.eclipse.jface.preference.PreferencePage; + +/** + * A preference block for folding of Shell Script commands. + */ +public class ShellCodeFoldingPreferenceBlock extends SourceCodeFoldingPreferenceBlock { + public ShellCodeFoldingPreferenceBlock(OverlayPreferenceStore store, PreferencePage page) { + super(store, page); + } + + @Override + protected String getInitiallyFoldMethodsText() { + return "Functions"; + } + + @Override + protected boolean supportsClassFolding() { + return false; + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/folding/ShellCommentFoldingBlockProvider.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/folding/ShellCommentFoldingBlockProvider.java new file mode 100644 index 0000000..6394773 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/folding/ShellCommentFoldingBlockProvider.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text.folding; + +import org.eclipse.dltk.sh.internal.ui.Activator; +import org.eclipse.dltk.sh.internal.ui.text.IShellPartitions; +import org.eclipse.dltk.ui.text.folding.IFoldingContent; +import org.eclipse.dltk.ui.text.folding.PartitioningFoldingBlockProvider; + +public class ShellCommentFoldingBlockProvider extends PartitioningFoldingBlockProvider { + + public ShellCommentFoldingBlockProvider() { + super(Activator.getDefault().getTextTools()); + } + + @Override + public void computeFoldableBlocks(IFoldingContent content) { + if (isFoldingComments()) { + computeBlocksForPartitionType(content, IShellPartitions.COMMENT_CONTENT_TYPE, FoldingBlockKind.COMMENT, + isCollapseComments()); + } + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/folding/ShellCommentFoldingPreferenceBlock.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/folding/ShellCommentFoldingPreferenceBlock.java new file mode 100644 index 0000000..60610ab --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/folding/ShellCommentFoldingPreferenceBlock.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2014 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Peter Palaga - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text.folding; + +import org.eclipse.dltk.ui.PreferenceConstants; +import org.eclipse.dltk.ui.preferences.OverlayPreferenceStore; +import org.eclipse.dltk.ui.preferences.PreferencesMessages; +import org.eclipse.dltk.ui.text.folding.DocumentationFoldingPreferenceBlock; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.swt.widgets.Group; + +/** + * A preference block for folding of Shell Script comments. + */ +public class ShellCommentFoldingPreferenceBlock extends DocumentationFoldingPreferenceBlock { + + public ShellCommentFoldingPreferenceBlock(OverlayPreferenceStore store, PreferencePage page) { + super(store, page); + } + + /** + * Overridden to add just the "Comments" checkbox rather than both + * "Comments" and "Header comments" as it is done in the super class. It is + * because we do not detect header comments and therefore we cannot fold + * them separately. + * + * @see org.eclipse.dltk.ui.text.folding.DocumentationFoldingPreferenceBlock#addInitiallyFoldOptions(org.eclipse.swt.widgets.Group) + */ + @Override + protected void addInitiallyFoldOptions(Group group) { + createCheckBox(group, PreferencesMessages.FoldingConfigurationBlock_initiallyFoldComments, + PreferenceConstants.EDITOR_FOLDING_INIT_COMMENTS); + } + +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/wizards/NewShellScriptFilePage.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/wizards/NewShellScriptFilePage.java new file mode 100644 index 0000000..5b894d5 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/wizards/NewShellScriptFilePage.java @@ -0,0 +1,22 @@ +package org.eclipse.dltk.sh.internal.ui.wizards; + +import org.eclipse.dltk.sh.core.ShelledNature; +import org.eclipse.dltk.ui.wizards.NewSourceModulePage; + +public class NewShellScriptFilePage extends NewSourceModulePage { + + @Override + protected String getPageTitle() { + return "Shell Script"; + } + + @Override + protected String getPageDescription() { + return "Create a new Shell Script."; + } + + @Override + protected String getRequiredNature() { + return ShelledNature.SHELLED_NATURE; + } +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/wizards/NewShellScriptFileWizard.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/wizards/NewShellScriptFileWizard.java new file mode 100644 index 0000000..f75689a --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/wizards/NewShellScriptFileWizard.java @@ -0,0 +1,18 @@ +package org.eclipse.dltk.sh.internal.ui.wizards; + +import org.eclipse.dltk.ui.DLTKUIPlugin; +import org.eclipse.dltk.ui.wizards.NewSourceModulePage; +import org.eclipse.dltk.ui.wizards.NewSourceModuleWizard; + +public class NewShellScriptFileWizard extends NewSourceModuleWizard { + + public NewShellScriptFileWizard() { + setWindowTitle("New Shell Script"); + setDialogSettings(DLTKUIPlugin.getDefault().getDialogSettings()); + } + + @Override + protected NewSourceModulePage createNewSourceModulePage() { + return new NewShellScriptFilePage(); + } +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/wizards/ShellScriptProjectWizard.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/wizards/ShellScriptProjectWizard.java new file mode 100644 index 0000000..db45435 --- /dev/null +++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/wizards/ShellScriptProjectWizard.java @@ -0,0 +1,41 @@ +package org.eclipse.dltk.sh.internal.ui.wizards; + +import org.eclipse.dltk.sh.core.ShelledNature; +import org.eclipse.dltk.ui.DLTKUIPlugin; +import org.eclipse.dltk.ui.wizards.ProjectWizard; +import org.eclipse.dltk.ui.wizards.ProjectWizardFirstPage; +import org.eclipse.dltk.ui.wizards.ProjectWizardSecondPage; + +public class ShellScriptProjectWizard extends ProjectWizard { + + public ShellScriptProjectWizard() { + setWindowTitle("New Shell Script Project"); + setDialogSettings(DLTKUIPlugin.getDefault().getDialogSettings()); + } + + @Override + public String getScriptNature() { + return ShelledNature.SHELLED_NATURE; + } + + @Override + public void addPages() { + super.addPages(); + ProjectWizardFirstPage firstPage = new ProjectWizardFirstPage() { + + @Override + protected boolean interpeterRequired() { + return false; + } + }; + + // First page + firstPage.setTitle("Shell Script Project"); + firstPage.setDescription("Create a new Shell Script project."); + addPage(firstPage); + + // Second page + ProjectWizardSecondPage secondPage = new ProjectWizardSecondPage(firstPage); + addPage(secondPage); + } +} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/Activator.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/Activator.java deleted file mode 100644 index 8121952..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/Activator.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui; - -import org.eclipse.dltk.sh.ui.text.ShellTextTools; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.osgi.framework.BundleContext; - -/** - * The activator class controls the plug-in life cycle - */ -public class Activator extends AbstractUIPlugin { - - // The shared instance - private static Activator plugin; - - // The plug-in ID - public static final String PLUGIN_ID = "org.eclipse.dltk.sh.ui"; - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static Activator getDefault() { - return plugin; - } - - private ShellTextTools fShellTextTools; - - public synchronized ShellTextTools getTextTools() { - if (fShellTextTools == null) { - fShellTextTools = new ShellTextTools(true); - } - return fShellTextTools; - } - - @Override - public void start(BundleContext context) throws Exception { - super.start(context); - plugin = this; - } - - @Override - public void stop(BundleContext context) throws Exception { - plugin = null; - super.stop(context); - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/IShellColorConstants.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/IShellColorConstants.java deleted file mode 100644 index ad4da18..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/IShellColorConstants.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui; - -import org.eclipse.dltk.ui.text.DLTKColorConstants; - -public interface IShellColorConstants { - String SHELL_COMMENT = DLTKColorConstants.DLTK_SINGLE_LINE_COMMENT; - String SHELL_DEFAULT = DLTKColorConstants.DLTK_DEFAULT; - String SHELL_DOUBLE_QUOTE = "SHELLED_interpolated_string"; - String SHELL_EVAL = DLTKColorConstants.DLTK_OPERATOR; - String SHELL_FUNCTION = DLTKColorConstants.DLTK_FUNCTION_DEFINITION; - String SHELL_HASHBANG = DLTKColorConstants.DLTK_MULTI_LINE_COMMENT; - String SHELL_KEYWORD = DLTKColorConstants.DLTK_KEYWORD; - String SHELL_SINGLE_QUOTE = DLTKColorConstants.DLTK_STRING; - String SHELL_VARIABLE = DLTKColorConstants.DLTK_ARGUMENT; - String SHELL_COMMAND = DLTKColorConstants.DLTK_BASE_CLASS; - String SHELL_TODO_TAG = DLTKColorConstants.TASK_TAG; -} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/LaunchConfigurationDelegate.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/LaunchConfigurationDelegate.java deleted file mode 100644 index 1fd24d1..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/LaunchConfigurationDelegate.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui; - -import org.eclipse.dltk.launching.AbstractScriptLaunchConfigurationDelegate; -import org.eclipse.dltk.sh.core.ShelledNature; - -public class LaunchConfigurationDelegate extends AbstractScriptLaunchConfigurationDelegate { - - @Override - public String getLanguageId() { - return ShelledNature.SHELLED_NATURE; - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/LaunchShortcut.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/LaunchShortcut.java deleted file mode 100644 index 8cb4874..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/LaunchShortcut.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui; - -import org.eclipse.debug.core.ILaunchConfigurationType; -import org.eclipse.dltk.internal.debug.ui.launcher.AbstractScriptLaunchShortcut; -import org.eclipse.dltk.sh.core.ShelledNature; - -public class LaunchShortcut extends AbstractScriptLaunchShortcut { - - @Override - protected ILaunchConfigurationType getConfigurationType() { - return getLaunchManager().getLaunchConfigurationType("org.eclipse.dltk.sh.ui.launchConfigurationType1"); - } - - @Override - protected String getNatureId() { - return ShelledNature.SHELLED_NATURE; - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/MainPreferencePage.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/MainPreferencePage.java deleted file mode 100644 index 95f2379..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/MainPreferencePage.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui; - -import org.eclipse.jface.preference.PreferencePage; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPreferencePage; - -public class MainPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { - - public MainPreferencePage() { - // TODO Auto-generated constructor stub - } - - public MainPreferencePage(String title) { - super(title); - // TODO Auto-generated constructor stub - } - - public MainPreferencePage(String title, ImageDescriptor image) { - super(title, image); - // TODO Auto-generated constructor stub - } - - @Override - protected Control createContents(Composite parent) { - // TODO Auto-generated method stub - return null; - } - - @Override - public void init(IWorkbench workbench) { - // TODO Auto-generated method stub - - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/ShellContentAssistPreference.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/ShellContentAssistPreference.java deleted file mode 100644 index add5502..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/ShellContentAssistPreference.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui; - -import org.eclipse.dltk.ui.text.ScriptTextTools; -import org.eclipse.dltk.ui.text.completion.ContentAssistPreference; - -public class ShellContentAssistPreference extends ContentAssistPreference { - private static ShellContentAssistPreference instance; - - public static ContentAssistPreference getDefault() { - if (instance == null) { - instance = new ShellContentAssistPreference(); - } - return instance; - } - - @Override - protected ScriptTextTools getTextTools() { - return Activator.getDefault().getTextTools(); - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/ShellTodoParserType.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/ShellTodoParserType.java deleted file mode 100644 index a5a91dd..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/ShellTodoParserType.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui; - -import org.eclipse.dltk.compiler.task.ITodoTaskPreferences; -import org.eclipse.dltk.compiler.task.TodoTaskPreferencesOnPreferenceLookupDelegate; -import org.eclipse.dltk.core.IScriptProject; -import org.eclipse.dltk.core.builder.AbstractTodoTaskBuildParticipantType; - -public class ShellTodoParserType extends AbstractTodoTaskBuildParticipantType { - - @Override - protected ITodoTaskPreferences getPreferences(IScriptProject project) { - return new TodoTaskPreferencesOnPreferenceLookupDelegate(Activator.PLUGIN_ID, project); - } -} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/ShelledUILanguageToolkit.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/ShelledUILanguageToolkit.java deleted file mode 100644 index 0b28058..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/ShelledUILanguageToolkit.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui; - -import org.eclipse.dltk.core.IDLTKLanguageToolkit; -import org.eclipse.dltk.sh.core.ShellScriptLanguageToolkit; -import org.eclipse.dltk.sh.ui.interpreter.ShellInterpreterPreferencePage; -import org.eclipse.dltk.ui.AbstractDLTKUILanguageToolkit; -import org.eclipse.jface.preference.IPreferenceStore; - -public class ShelledUILanguageToolkit extends AbstractDLTKUILanguageToolkit { - @Override - public IDLTKLanguageToolkit getCoreToolkit() { - return ShellScriptLanguageToolkit.getDefault(); - } - - @Override - public IPreferenceStore getPreferenceStore() { - return Activator.getDefault().getPreferenceStore(); - } - - @Override - public String getInterpreterPreferencePage() { - return ShellInterpreterPreferencePage.PAGE_ID; - } -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/ShelledUIPreferenceInitializer.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/ShelledUIPreferenceInitializer.java deleted file mode 100644 index 7c5931c..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/ShelledUIPreferenceInitializer.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui; - -import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; -import org.eclipse.core.runtime.preferences.DefaultScope; -import org.eclipse.dltk.compiler.task.TaskTagUtils; -import org.eclipse.dltk.ui.CodeFormatterConstants; -import org.eclipse.dltk.ui.PreferenceConstants; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.preference.PreferenceConverter; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.ui.editors.text.EditorsUI; - -public class ShelledUIPreferenceInitializer extends AbstractPreferenceInitializer { - - @Override - public void initializeDefaultPreferences() { - IPreferenceStore store = Activator.getDefault().getPreferenceStore(); - - EditorsUI.useAnnotationsPreferencePage(store); - EditorsUI.useQuickDiffPreferencePage(store); - - // Initialize DLTK default values - PreferenceConstants.initializeDefaultValues(store); - - // Initialize SHELL constants - PreferenceConverter.setDefault(store, IShellColorConstants.SHELL_COMMENT, new RGB(136, 0, 136)); - PreferenceConverter.setDefault(store, IShellColorConstants.SHELL_HASHBANG, new RGB(136, 136, 136)); - PreferenceConverter.setDefault(store, IShellColorConstants.SHELL_KEYWORD, new RGB(144, 4, 86)); - PreferenceConverter.setDefault(store, IShellColorConstants.SHELL_SINGLE_QUOTE, new RGB(13, 109, 160)); - PreferenceConverter.setDefault(store, IShellColorConstants.SHELL_DOUBLE_QUOTE, new RGB(13, 109, 24)); - PreferenceConverter.setDefault(store, IShellColorConstants.SHELL_EVAL, new RGB(205, 30, 30)); - PreferenceConverter.setDefault(store, IShellColorConstants.SHELL_FUNCTION, new RGB(255, 127, 63)); - PreferenceConverter.setDefault(store, IShellColorConstants.SHELL_COMMAND, new RGB(255, 127, 63)); - PreferenceConverter.setDefault(store, IShellColorConstants.SHELL_VARIABLE, new RGB(0, 0, 156)); - - PreferenceConverter.setDefault(store, IShellColorConstants.SHELL_TODO_TAG, new RGB(127, 159, 191)); - store.setDefault(IShellColorConstants.SHELL_TODO_TAG + PreferenceConstants.EDITOR_BOLD_SUFFIX, true); - - store.setDefault(IShellColorConstants.SHELL_COMMENT + PreferenceConstants.EDITOR_BOLD_SUFFIX, false); - store.setDefault(IShellColorConstants.SHELL_COMMENT + PreferenceConstants.EDITOR_ITALIC_SUFFIX, true); - store.setDefault(IShellColorConstants.SHELL_HASHBANG + PreferenceConstants.EDITOR_ITALIC_SUFFIX, true); - - store.setDefault(IShellColorConstants.SHELL_KEYWORD + PreferenceConstants.EDITOR_BOLD_SUFFIX, true); - store.setDefault(IShellColorConstants.SHELL_KEYWORD + PreferenceConstants.EDITOR_ITALIC_SUFFIX, false); - - store.setDefault(PreferenceConstants.EDITOR_TAB_WIDTH, 8); - store.setDefault(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE, true); - - store.setDefault(CodeFormatterConstants.FORMATTER_TAB_CHAR, CodeFormatterConstants.TAB); - store.setDefault(CodeFormatterConstants.FORMATTER_TAB_SIZE, "4"); - store.setDefault(CodeFormatterConstants.FORMATTER_INDENTATION_SIZE, "4"); - - /* folding */ - store.setDefault(PreferenceConstants.EDITOR_FOLDING_ENABLED, true); - store.setDefault(PreferenceConstants.EDITOR_FOLDING_LINES_LIMIT, 2); - store.setDefault(PreferenceConstants.EDITOR_COMMENTS_FOLDING_ENABLED, true); - store.setDefault(PreferenceConstants.EDITOR_DOCS_FOLDING_ENABLED, true); - store.setDefault(PreferenceConstants.EDITOR_FOLDING_INIT_COMMENTS, true); - - TaskTagUtils.initializeDefaultValues(DefaultScope.INSTANCE.getNode(Activator.PLUGIN_ID)); - } -} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/commands/AbstractProjectHandler.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/commands/AbstractProjectHandler.java deleted file mode 100644 index cb48cb2..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/commands/AbstractProjectHandler.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Mat Booth and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.commands; - -import java.util.Iterator; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.handlers.HandlerUtil; - -/** - * An abstract command handler that iterates through the current selection - * looking for projects resources to save us from having this code in every - * handler that wants to manipulate projects. - */ -public abstract class AbstractProjectHandler extends AbstractHandler { - - @Override - public Object execute(ExecutionEvent event) { - IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event); - Iterator iterator = selection.iterator(); - while (iterator.hasNext()) { - Object element = iterator.next(); - IProject project = null; - if (element instanceof IProject) { - project = (IProject) element; - } else if (element instanceof IAdaptable) { - project = (IProject)((IAdaptable) element).getAdapter(IProject.class); - } - if (project != null) { - fettleProject(project); - } - } - return null; - } - - /** - * To be implemented by sub-classes to perform actions on a project. This - * will be called once for every project resource that is currently - * selected. - * - * @param project - * a project resource for manipulation - */ - protected abstract void fettleProject(IProject project); -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/commands/AddNature.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/commands/AddNature.java deleted file mode 100644 index 65a9d64..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/commands/AddNature.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Mat Booth and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.commands; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.dltk.sh.core.ShelledNature; - -/** - * Implementation of the project handler that adds the ShellEd nature to a - * project. - */ -public class AddNature extends AbstractProjectHandler { - - @Override - protected void fettleProject(IProject project) { - try { - // Get the project description - IProjectDescription description = project.getDescription(); - String[] natures = description.getNatureIds(); - - // Add the nature to the list - String[] newNatures = new String[natures.length + 1]; - System.arraycopy(natures, 0, newNatures, 0, natures.length); - newNatures[natures.length] = ShelledNature.SHELLED_NATURE; - - // Set the project description - description.setNatureIds(newNatures); - project.setDescription(description, null); - } catch (CoreException e) { - e.printStackTrace(); - } - } -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/commands/NaturePropertyTester.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/commands/NaturePropertyTester.java deleted file mode 100644 index 3578bf8..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/commands/NaturePropertyTester.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Mat Booth and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.commands; - -import org.eclipse.core.expressions.PropertyTester; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.dltk.sh.core.ShelledNature; - -/** - * A property tester that returns true if the project containing any given - * resource is a ShellEd-natured project. - */ -public class NaturePropertyTester extends PropertyTester { - - // Properties made available for test by this tester - private static final String HAS_SHELLED_NATURE = "hasShellEdNature"; //$NON-NLS-1$ - - @Override - public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { - IResource resource = (IResource)((IAdaptable) receiver).getAdapter(IResource.class); - if (resource == null) { - return false; - } - if (property.equals(HAS_SHELLED_NATURE)) { - try { - IProject proj = resource.getProject(); - return proj.isAccessible() && proj.hasNature(ShelledNature.SHELLED_NATURE); - } catch (CoreException e) { - return false; - } - } - return false; - } -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/commands/RemoveNature.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/commands/RemoveNature.java deleted file mode 100644 index 1927e4e..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/commands/RemoveNature.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Mat Booth and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.commands; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.dltk.sh.core.ShelledNature; - -/** - * Implementation of the project handler that removes the ShellEd nature from a - * project. - */ -public class RemoveNature extends AbstractProjectHandler { - - @Override - protected void fettleProject(IProject project) { - try { - // Get the project description - IProjectDescription description = project.getDescription(); - String[] natures = description.getNatureIds(); - - // Filter the nature out of the list - List newNatures = new ArrayList<>(); - for (String nature : natures) { - if (!ShelledNature.SHELLED_NATURE.equals(nature)) { - newNatures.add(nature); - } - } - - // Set the project description - description.setNatureIds(newNatures.toArray(new String[newNatures.size()])); - project.setDescription(description, null); - } catch (CoreException e) { - e.printStackTrace(); - } - } -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/commands/ShowManHandler.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/commands/ShowManHandler.java deleted file mode 100644 index 1b65dba..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/commands/ShowManHandler.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.commands; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.jface.text.TextSelection; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.linuxtools.man.views.ManView; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.handlers.HandlerUtil; - -/** - * A command handler that opens the Man Page view and tries to show the man page - * for whatever text is currently highlighted. - */ -public class ShowManHandler extends AbstractHandler { - - @Override - public Object execute(ExecutionEvent event) { - try { - ISelection selection = HandlerUtil.getActiveEditor(event).getEditorSite().getSelectionProvider() - .getSelection(); - String manPage = ""; - if (selection instanceof TextSelection) { - TextSelection textSelection = (TextSelection) selection; - manPage = textSelection.getText(); - } - - if (!manPage.isEmpty()) { - ManView view = (ManView) HandlerUtil.getActiveWorkbenchWindow(event).getActivePage() - .showView(ManView.ID); - view.setManPageName(manPage); - } - } catch (PartInitException e) { - e.printStackTrace(); - } - return null; - } -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/completion/ShellCompletionEngine.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/completion/ShellCompletionEngine.java deleted file mode 100644 index cbb948a..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/completion/ShellCompletionEngine.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.completion; - -import org.eclipse.dltk.codeassist.ScriptCompletionEngine; -import org.eclipse.dltk.compiler.env.IModuleSource; -import org.eclipse.dltk.core.CompletionProposal; -import org.eclipse.dltk.core.DLTKCore; -import org.eclipse.dltk.core.IModelElement; -import org.eclipse.dltk.core.IModelElementVisitor; -import org.eclipse.dltk.core.ModelException; -import org.eclipse.dltk.sh.ui.text.ShellCodeScanner; - -public class ShellCompletionEngine extends ScriptCompletionEngine { - - private int actualCompletionPosition; - - @Override - public void complete(IModuleSource module, int position, int pos) { - - this.actualCompletionPosition = position; - this.offset = pos; - String temp = module.getSourceContents().substring(0, position); - int lastSpace = temp.lastIndexOf(' '); - int lastNewline = temp.lastIndexOf('\n'); - String complPrefix = temp.substring(lastSpace > lastNewline ? lastSpace : lastNewline).trim(); - this.requestor.beginReporting(); - for (String keyword : ShellCodeScanner.KEYWORDS) { - if (keyword.startsWith(complPrefix)) { - createProposal(keyword, null); - } - } - for (String command : ShellCodeScanner.getCommands()) { - if (command.startsWith(complPrefix)) { - createProposal(command, null); - } - } - - // Completion for model elements. - try { - module.getModelElement().accept(new IModelElementVisitor() { - @Override - public boolean visit(IModelElement element) { - if (element.getElementType() > IModelElement.SOURCE_MODULE) { - createProposal(element.getElementName(), element); - } - return true; - } - }); - } catch (ModelException e) { - if (DLTKCore.DEBUG) { - e.printStackTrace(); - } - } - this.requestor.endReporting(); - } - - private void createProposal(String name, IModelElement element) { - CompletionProposal proposal = this.createProposal(CompletionProposal.KEYWORD, this.actualCompletionPosition); - proposal.setName(name); - proposal.setCompletion(name); - proposal.setReplaceRange(actualCompletionPosition - offset, actualCompletionPosition - offset); - proposal.setRelevance(20); - proposal.setModelElement(element); - this.requestor.accept(proposal); - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/completion/ShellCompletionProcessor.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/completion/ShellCompletionProcessor.java deleted file mode 100644 index d9ebae4..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/completion/ShellCompletionProcessor.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.completion; - -import org.eclipse.dltk.sh.core.ShelledNature; -import org.eclipse.dltk.ui.text.completion.ScriptCompletionProcessor; -import org.eclipse.jface.text.contentassist.ContentAssistant; -import org.eclipse.ui.IEditorPart; - -public class ShellCompletionProcessor extends ScriptCompletionProcessor { - public ShellCompletionProcessor(IEditorPart editor, ContentAssistant assistant, String partition) { - super(editor, assistant, partition); - } - - @Override - protected String getNatureId() { - return ShelledNature.SHELLED_NATURE; - } - -} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/completion/ShellCompletionProposal.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/completion/ShellCompletionProposal.java deleted file mode 100644 index 07212ec..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/completion/ShellCompletionProposal.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.completion; - -import org.eclipse.dltk.sh.ui.Activator; -import org.eclipse.dltk.ui.PreferenceConstants; -import org.eclipse.dltk.ui.text.completion.ScriptCompletionProposal; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.swt.graphics.Image; - -public class ShellCompletionProposal extends ScriptCompletionProposal { - public ShellCompletionProposal(String replacementString, int replacementOffset, int replacementLength, Image image, - String displayString, int relevance) { - super(replacementString, replacementOffset, replacementLength, image, displayString, relevance); - } - - public ShellCompletionProposal(String replacementString, int replacementOffset, int replacementLength, Image image, - String displayString, int relevance, boolean isInDoc) { - super(replacementString, replacementOffset, replacementLength, image, displayString, relevance, isInDoc); - } - - @Override - protected boolean isSmartTrigger(char trigger) { - if (trigger == '$') { - return true; - } - return false; - } - - @Override - protected boolean insertCompletion() { - IPreferenceStore preference = Activator.getDefault().getPreferenceStore(); - return preference.getBoolean(PreferenceConstants.CODEASSIST_INSERT_COMPLETION); - } -} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/completion/ShellCompletionProposalCollector.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/completion/ShellCompletionProposalCollector.java deleted file mode 100644 index 0074c56..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/completion/ShellCompletionProposalCollector.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.completion; - -import org.eclipse.dltk.core.IScriptProject; -import org.eclipse.dltk.core.ISourceModule; -import org.eclipse.dltk.ui.text.completion.ScriptCompletionProposal; -import org.eclipse.dltk.ui.text.completion.ScriptCompletionProposalCollector; -import org.eclipse.swt.graphics.Image; - -public class ShellCompletionProposalCollector extends ScriptCompletionProposalCollector { - - public ShellCompletionProposalCollector(ISourceModule module) { - super(module); - } - - @Override - protected ScriptCompletionProposal createOverrideCompletionProposal(IScriptProject scriptProject, - ISourceModule compilationUnit, String name, String[] paramTypes, int start, int length, String label, - String string) { - // TODO Auto-generated method stub - return null; - } - - @Override - protected ScriptCompletionProposal createScriptCompletionProposal(String completion, int replaceStart, int length, - Image image, String displayString, int i) { - return new ShellCompletionProposal(completion, replaceStart, length, image, displayString, i); - - } - - @Override - protected ScriptCompletionProposal createScriptCompletionProposal(String completion, int replaceStart, int length, - Image image, String displayString, int i, boolean isInDoc) { - return new ShellCompletionProposal(completion, replaceStart, length, image, displayString, i); - } - - @Override - protected char[] getVarTrigger() { - return new char[] { '$' }; - } - - @Override - protected String getNatureId() { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/completion/ShellCompletionProposalComputer.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/completion/ShellCompletionProposalComputer.java deleted file mode 100644 index 41f6435..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/completion/ShellCompletionProposalComputer.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.completion; - -import org.eclipse.dltk.ui.text.completion.ScriptCompletionProposalCollector; -import org.eclipse.dltk.ui.text.completion.ScriptCompletionProposalComputer; -import org.eclipse.dltk.ui.text.completion.ScriptContentAssistInvocationContext; -import org.eclipse.jface.text.templates.TemplateCompletionProcessor; - -public class ShellCompletionProposalComputer extends ScriptCompletionProposalComputer { - - public ShellCompletionProposalComputer() { - - } - - @Override - protected ScriptCompletionProposalCollector createCollector(ScriptContentAssistInvocationContext context) { - return new ShellCompletionProposalCollector(context.getSourceModule()); - } - - @Override - protected TemplateCompletionProcessor createTemplateProposalComputer(ScriptContentAssistInvocationContext context) { - return null; - } -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/editor/ShellDocumentSetupParticipant.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/editor/ShellDocumentSetupParticipant.java deleted file mode 100644 index beeb33b..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/editor/ShellDocumentSetupParticipant.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.editor; - -import org.eclipse.core.filebuffers.IDocumentSetupParticipant; -import org.eclipse.dltk.sh.ui.Activator; -import org.eclipse.dltk.sh.ui.text.IShellPartitions; -import org.eclipse.dltk.sh.ui.text.ShellTextTools; -import org.eclipse.jface.text.IDocument; - -public class ShellDocumentSetupParticipant implements IDocumentSetupParticipant { - - @Override - public void setup(IDocument document) { - ShellTextTools tools = Activator.getDefault().getTextTools(); - tools.setupDocumentPartitioner(document, IShellPartitions.SHELL_PARTITIONING); - } -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/editor/ShellScriptEditor.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/editor/ShellScriptEditor.java deleted file mode 100644 index e4ce945..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/editor/ShellScriptEditor.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.editor; - -import org.eclipse.dltk.core.IDLTKLanguageToolkit; -import org.eclipse.dltk.internal.ui.editor.ScriptEditor; -import org.eclipse.dltk.sh.core.ShellScriptLanguageToolkit; -import org.eclipse.dltk.sh.ui.Activator; -import org.eclipse.dltk.sh.ui.text.IShellPartitions; -import org.eclipse.dltk.ui.text.ScriptTextTools; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentExtension3; -import org.eclipse.ui.IEditorInput; - -public class ShellScriptEditor extends ScriptEditor { - - public static final String EDITOR_CONTEXT = "#ShellScriptEditorContext"; - - public static final String EDITOR_ID = "org.eclipse.dltk.sh.ui.editor"; - - @Override - protected void connectPartitioningToElement(IEditorInput input, IDocument document) { - if (document instanceof IDocumentExtension3) { - IDocumentExtension3 extension = (IDocumentExtension3) document; - if (extension.getDocumentPartitioner(IShellPartitions.SHELL_PARTITIONING) == null) { - ShellDocumentSetupParticipant participant = new ShellDocumentSetupParticipant(); - participant.setup(document); - } - } - } - - @Override - public String getEditorId() { - return EDITOR_ID; - } - - @Override - public IDLTKLanguageToolkit getLanguageToolkit() { - return ShellScriptLanguageToolkit.getDefault(); - } - - @Override - public IPreferenceStore getScriptPreferenceStore() { - return Activator.getDefault().getPreferenceStore(); - } - - @Override - public ScriptTextTools getTextTools() { - return Activator.getDefault().getTextTools(); - } - - @Override - protected void initializeEditor() { - super.initializeEditor(); - setEditorContextMenuId(EDITOR_CONTEXT); - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/editor/ShellSourceViewerConfiguration.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/editor/ShellSourceViewerConfiguration.java deleted file mode 100644 index 3019e09..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/editor/ShellSourceViewerConfiguration.java +++ /dev/null @@ -1,233 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009-2010 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.editor; - -import java.util.ArrayList; - -import org.eclipse.dltk.sh.ui.Activator; -import org.eclipse.dltk.sh.ui.IShellColorConstants; -import org.eclipse.dltk.sh.ui.ShellContentAssistPreference; -import org.eclipse.dltk.sh.ui.completion.ShellCompletionProcessor; -import org.eclipse.dltk.sh.ui.text.DoubleQuoteScanner; -import org.eclipse.dltk.sh.ui.text.EvalScanner; -import org.eclipse.dltk.sh.ui.text.IShellPartitions; -import org.eclipse.dltk.sh.ui.text.IndentType; -import org.eclipse.dltk.sh.ui.text.ScriptAutoIndentStrategy; -import org.eclipse.dltk.sh.ui.text.ShellCodeScanner; -import org.eclipse.dltk.sh.ui.text.WhitespaceDetector; -import org.eclipse.dltk.ui.text.AbstractScriptScanner; -import org.eclipse.dltk.ui.text.IColorManager; -import org.eclipse.dltk.ui.text.ScriptOutlineInformationControl; -import org.eclipse.dltk.ui.text.ScriptPresentationReconciler; -import org.eclipse.dltk.ui.text.ScriptSourceViewerConfiguration; -import org.eclipse.dltk.ui.text.SingleTokenScriptScanner; -import org.eclipse.dltk.ui.text.completion.ContentAssistPreference; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.IAutoEditStrategy; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IInformationControl; -import org.eclipse.jface.text.IInformationControlCreator; -import org.eclipse.jface.text.contentassist.ContentAssistant; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.text.presentation.IPresentationReconciler; -import org.eclipse.jface.text.presentation.PresentationReconciler; -import org.eclipse.jface.text.rules.DefaultDamagerRepairer; -import org.eclipse.jface.text.rules.IRule; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.IWordDetector; -import org.eclipse.jface.text.rules.Token; -import org.eclipse.jface.text.rules.WhitespaceRule; -import org.eclipse.jface.text.rules.WordRule; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.texteditor.ITextEditor; - -public class ShellSourceViewerConfiguration extends ScriptSourceViewerConfiguration { - - private static IRule getKeywords(IToken keywordToken, final String[] words, IToken defaultToken) { - WordRule wordL = new WordRule(new IWordDetector() { - - @Override - public boolean isWordPart(char c) { - return !Character.isWhitespace(c); - } - - @Override - public boolean isWordStart(char c) { - return !Character.isWhitespace(c); - } - }, defaultToken); - - for (String word : words) { - wordL.addWord(word, keywordToken); - } - return wordL; - } - - // Scanners for all the various content types provided by the partitioner - private AbstractScriptScanner fCodeScanner; - private AbstractScriptScanner fCommentScanner; - private AbstractScriptScanner fDoubleQuoteScanner; - private AbstractScriptScanner fParamScanner; - private AbstractScriptScanner fEvalScanner; - private AbstractScriptScanner fHashbangScanner; - private AbstractScriptScanner fFunctionScanner; - private AbstractScriptScanner fSingleQuoteScanner; - - public ShellSourceViewerConfiguration(IColorManager colorManager, IPreferenceStore preferenceStore, - ITextEditor editor, String partitioning) { - super(colorManager, preferenceStore, editor, partitioning); - } - - @Override - public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) { - ScriptAutoIndentStrategy strategy = new ScriptAutoIndentStrategy(); - - ArrayList rules = new ArrayList<>(); - rules.add(new WhitespaceRule(new WhitespaceDetector())); - rules.add(getKeywords(new Token(IndentType.INCREMENT), new String[] { "do", "case", "{", "then" }, - Token.UNDEFINED)); - rules.add(getKeywords(new Token(IndentType.DECREMENT), new String[] { "done", "esac", "}", "fi" }, - Token.UNDEFINED)); - rules.add(getKeywords(new Token(IndentType.INFLEXION), new String[] { "else" }, Token.UNDEFINED)); - - strategy.setRules(rules.toArray(new IRule[0])); - - return new IAutoEditStrategy[] { strategy }; - } - - @Override - protected ContentAssistPreference getContentAssistPreference() { - return ShellContentAssistPreference.getDefault(); - } - - @Override - protected IInformationControlCreator getOutlinePresenterControlCreator(ISourceViewer sourceViewer, - final String commandId) { - return new IInformationControlCreator() { - @Override - public IInformationControl createInformationControl(Shell parent) { - int shellStyle = SWT.RESIZE; - int treeStyle = SWT.V_SCROLL | SWT.H_SCROLL; - return new ScriptOutlineInformationControl(parent, shellStyle, treeStyle, commandId, - Activator.getDefault().getPreferenceStore()); - } - }; - } - - @Override - public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { - PresentationReconciler reconciler = new ScriptPresentationReconciler(); - reconciler.setDocumentPartitioning(this.getConfiguredDocumentPartitioning(sourceViewer)); - - DefaultDamagerRepairer dr; - - dr = new DefaultDamagerRepairer(this.fCodeScanner); - reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); - reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); - - dr = new DefaultDamagerRepairer(this.fHashbangScanner); - reconciler.setDamager(dr, IShellPartitions.HASHBANG_CONTENT_TYPE); - reconciler.setRepairer(dr, IShellPartitions.HASHBANG_CONTENT_TYPE); - - dr = new DefaultDamagerRepairer(this.fParamScanner); - reconciler.setDamager(dr, IShellPartitions.PARAM_CONTENT_TYPE); - reconciler.setRepairer(dr, IShellPartitions.PARAM_CONTENT_TYPE); - - dr = new DefaultDamagerRepairer(this.fFunctionScanner); - reconciler.setDamager(dr, IShellPartitions.FUNCTION_CONTENT_TYPE); - reconciler.setRepairer(dr, IShellPartitions.FUNCTION_CONTENT_TYPE); - - dr = new DefaultDamagerRepairer(this.fSingleQuoteScanner); - reconciler.setDamager(dr, IShellPartitions.SINGLE_QUOTE_CONTENT_TYPE); - reconciler.setRepairer(dr, IShellPartitions.SINGLE_QUOTE_CONTENT_TYPE); - - dr = new DefaultDamagerRepairer(this.fDoubleQuoteScanner); - reconciler.setDamager(dr, IShellPartitions.DOUBLE_QUOTE_CONTENT_TYPE); - reconciler.setRepairer(dr, IShellPartitions.DOUBLE_QUOTE_CONTENT_TYPE); - - dr = new DefaultDamagerRepairer(this.fEvalScanner); - reconciler.setDamager(dr, IShellPartitions.EVAL_CONTENT_TYPE); - reconciler.setRepairer(dr, IShellPartitions.EVAL_CONTENT_TYPE); - - dr = new DefaultDamagerRepairer(this.fCommentScanner); - reconciler.setDamager(dr, IShellPartitions.COMMENT_CONTENT_TYPE); - reconciler.setRepairer(dr, IShellPartitions.COMMENT_CONTENT_TYPE); - - return reconciler; - } - - // This method called from base class. - @Override - protected void initializeScanners() { - // This is our code scanner - this.fCodeScanner = new ShellCodeScanner(this.getColorManager(), this.fPreferenceStore); - // This is default scanners for partitions with same color. - this.fFunctionScanner = new SingleTokenScriptScanner(this.getColorManager(), this.fPreferenceStore, - IShellColorConstants.SHELL_FUNCTION); - this.fHashbangScanner = new SingleTokenScriptScanner(this.getColorManager(), this.fPreferenceStore, - IShellColorConstants.SHELL_HASHBANG); - this.fSingleQuoteScanner = new SingleTokenScriptScanner(this.getColorManager(), this.fPreferenceStore, - IShellColorConstants.SHELL_SINGLE_QUOTE); - this.fDoubleQuoteScanner = new DoubleQuoteScanner(this.getColorManager(), this.fPreferenceStore); - this.fParamScanner = new SingleTokenScriptScanner(this.getColorManager(), this.fPreferenceStore, - IShellColorConstants.SHELL_VARIABLE); - this.fEvalScanner = new EvalScanner(this.getColorManager(), this.fPreferenceStore); - this.fCommentScanner = createCommentScanner(IShellColorConstants.SHELL_COMMENT, - IShellColorConstants.SHELL_TODO_TAG); - } - - @Override - protected void alterContentAssistant(ContentAssistant assistant) { - IContentAssistProcessor scriptProcessor = new ShellCompletionProcessor(getEditor(), assistant, - IDocument.DEFAULT_CONTENT_TYPE); - assistant.setContentAssistProcessor(scriptProcessor, IDocument.DEFAULT_CONTENT_TYPE); - } - - @Override - public boolean affectsTextPresentation(PropertyChangeEvent event) { - return fCodeScanner.affectsBehavior(event) || fCommentScanner.affectsBehavior(event) - || fDoubleQuoteScanner.affectsBehavior(event) || fSingleQuoteScanner.affectsBehavior(event) - || fFunctionScanner.affectsBehavior(event) || fParamScanner.affectsBehavior(event) - || fEvalScanner.affectsBehavior(event) || fHashbangScanner.affectsBehavior(event); - } - - @Override - public void handlePropertyChangeEvent(PropertyChangeEvent event) { - if (fCodeScanner.affectsBehavior(event)) { - fCodeScanner.adaptToPreferenceChange(event); - } - if (fCommentScanner.affectsBehavior(event)) { - fCommentScanner.adaptToPreferenceChange(event); - } - if (fDoubleQuoteScanner.affectsBehavior(event)) { - fDoubleQuoteScanner.adaptToPreferenceChange(event); - } - if (fSingleQuoteScanner.affectsBehavior(event)) { - fSingleQuoteScanner.adaptToPreferenceChange(event); - } - if (fFunctionScanner.affectsBehavior(event)) { - fFunctionScanner.adaptToPreferenceChange(event); - } - if (fParamScanner.affectsBehavior(event)) { - fParamScanner.adaptToPreferenceChange(event); - } - if (fEvalScanner.affectsBehavior(event)) { - fEvalScanner.adaptToPreferenceChange(event); - } - if (fHashbangScanner.affectsBehavior(event)) { - fHashbangScanner.adaptToPreferenceChange(event); - } - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/AddShellScriptInterpreterDialog.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/AddShellScriptInterpreterDialog.java deleted file mode 100644 index 8a4c47e..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/AddShellScriptInterpreterDialog.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.interpreter; - -import org.eclipse.dltk.internal.debug.ui.interpreters.AbstractInterpreterLibraryBlock; -import org.eclipse.dltk.internal.debug.ui.interpreters.AddScriptInterpreterDialog; -import org.eclipse.dltk.internal.debug.ui.interpreters.IAddInterpreterDialogRequestor; -import org.eclipse.dltk.launching.IInterpreterInstall; -import org.eclipse.dltk.launching.IInterpreterInstallType; -import org.eclipse.swt.widgets.Shell; - -public class AddShellScriptInterpreterDialog extends AddScriptInterpreterDialog { - public AddShellScriptInterpreterDialog(IAddInterpreterDialogRequestor requestor, Shell shell, - IInterpreterInstallType[] interpreterInstallTypes, IInterpreterInstall editedInterpreter) { - super(requestor, shell, interpreterInstallTypes, editedInterpreter); - } - - @Override - protected AbstractInterpreterLibraryBlock createLibraryBlock(AddScriptInterpreterDialog dialog) { - return new ShellScriptInterpreterLibraryBlock(dialog); - } -} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellInterpreterPreferencePage.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellInterpreterPreferencePage.java deleted file mode 100644 index be5f1e2..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellInterpreterPreferencePage.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.interpreter; - -import org.eclipse.dltk.internal.debug.ui.interpreters.InterpretersBlock; -import org.eclipse.dltk.internal.debug.ui.interpreters.ScriptInterpreterPreferencePage; - -public class ShellInterpreterPreferencePage extends ScriptInterpreterPreferencePage { - - public static final String PAGE_ID = "org.eclipse.dltk.sh.ui.preferences.interpreters"; - - @Override - public InterpretersBlock createInterpretersBlock() { - return new ShellScriptInterpretersBlock(); - } -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellMainLaunchConfigurationTab.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellMainLaunchConfigurationTab.java deleted file mode 100644 index 953b297..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellMainLaunchConfigurationTab.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.interpreter; - -import org.eclipse.dltk.core.PreferencesLookupDelegate; -import org.eclipse.dltk.debug.ui.launchConfigurations.MainLaunchConfigurationTab; -import org.eclipse.dltk.sh.core.ShelledNature; - -public class ShellMainLaunchConfigurationTab extends MainLaunchConfigurationTab { - - public ShellMainLaunchConfigurationTab(String mode) { - super(mode); - } - - @Override - protected boolean breakOnFirstLinePrefEnabled(PreferencesLookupDelegate delegate) { - return false; - } - - @Override - protected boolean dbpgLoggingPrefEnabled(PreferencesLookupDelegate delegate) { - return false; - } - - @Override - public String getNatureID() { - return ShelledNature.SHELLED_NATURE; - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellScriptInstall.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellScriptInstall.java deleted file mode 100644 index ce6c9a6..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellScriptInstall.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.interpreter; - -import org.eclipse.dltk.internal.launching.StandardInterpreterRunner; -import org.eclipse.dltk.launching.AbstractInterpreterInstall; -import org.eclipse.dltk.launching.IInterpreterInstallType; -import org.eclipse.dltk.launching.IInterpreterRunner; -import org.eclipse.dltk.sh.core.ShelledNature; - -public class ShellScriptInstall extends AbstractInterpreterInstall { - public ShellScriptInstall(IInterpreterInstallType type, String id) { - super(type, id); - } - - @Override - public String getNatureId() { - return ShelledNature.SHELLED_NATURE; - } - - @Override - public IInterpreterRunner getInterpreterRunner(String mode) { - return new StandardInterpreterRunner(this); - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellScriptInstallType.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellScriptInstallType.java deleted file mode 100644 index 2437b8d..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellScriptInstallType.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.interpreter; - -import org.eclipse.core.runtime.ILog; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.dltk.core.environment.IDeployment; -import org.eclipse.dltk.core.environment.IFileHandle; -import org.eclipse.dltk.internal.launching.AbstractInterpreterInstallType; -import org.eclipse.dltk.launching.EnvironmentVariable; -import org.eclipse.dltk.launching.IInterpreterInstall; -import org.eclipse.dltk.launching.LibraryLocation; -import org.eclipse.dltk.sh.core.ShelledNature; -import org.eclipse.dltk.sh.ui.Activator; - -public class ShellScriptInstallType extends AbstractInterpreterInstallType { - private static final String[] INTERPRETER_NAMES = { "sh", "bash", "zsh", "dash", "ksh", "tcsh", "csh" }; - - @Override - protected IPath createPathFile(IDeployment deployment) { - return null; - } - - @Override - public synchronized LibraryLocation[] getDefaultLibraryLocations(IFileHandle installLocation, - EnvironmentVariable[] variables, IProgressMonitor monitor) { - return new LibraryLocation[0]; - } - - @Override - protected IInterpreterInstall doCreateInterpreterInstall(String id) { - return new ShellScriptInstall(this, id); - } - - @Override - protected ILog getLog() { - return Activator.getDefault().getLog(); - } - - @Override - public String getName() { - return "Shell Interpreter"; - } - - @Override - public String getNatureId() { - return ShelledNature.SHELLED_NATURE; - } - - @Override - protected String getPluginId() { - return Activator.PLUGIN_ID; - } - - @Override - protected String[] getPossibleInterpreterNames() { - return INTERPRETER_NAMES; - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellScriptInterpreterLibraryBlock.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellScriptInterpreterLibraryBlock.java deleted file mode 100644 index 36fd0ec..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellScriptInterpreterLibraryBlock.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.interpreter; - -import org.eclipse.dltk.internal.debug.ui.interpreters.AbstractInterpreterLibraryBlock; -import org.eclipse.dltk.internal.debug.ui.interpreters.AddScriptInterpreterDialog; -import org.eclipse.dltk.internal.debug.ui.interpreters.LibraryLabelProvider; -import org.eclipse.jface.viewers.IBaseLabelProvider; - -public class ShellScriptInterpreterLibraryBlock extends AbstractInterpreterLibraryBlock { - public ShellScriptInterpreterLibraryBlock(AddScriptInterpreterDialog d) { - super(d); - } - - @Override - protected IBaseLabelProvider getLabelProvider() { - return new LibraryLabelProvider(); - } -} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellScriptInterpretersBlock.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellScriptInterpretersBlock.java deleted file mode 100644 index c90c543..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellScriptInterpretersBlock.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.interpreter; - -import org.eclipse.dltk.core.environment.IEnvironment; -import org.eclipse.dltk.internal.debug.ui.interpreters.AddScriptInterpreterDialog; -import org.eclipse.dltk.internal.debug.ui.interpreters.InterpretersBlock; -import org.eclipse.dltk.launching.IInterpreterInstall; -import org.eclipse.dltk.launching.ScriptRuntime; -import org.eclipse.dltk.sh.core.ShelledNature; - -public class ShellScriptInterpretersBlock extends InterpretersBlock { - @Override - protected AddScriptInterpreterDialog createInterpreterDialog(IEnvironment environment, - IInterpreterInstall standin) { - AddShellScriptInterpreterDialog dialog = new AddShellScriptInterpreterDialog(this, getShell(), - ScriptRuntime.getInterpreterInstallTypes(getCurrentNature()), standin); - dialog.setEnvironment(environment); - return dialog; - } - - @Override - protected String getCurrentNature() { - return ShelledNature.SHELLED_NATURE; - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellTabGroup.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellTabGroup.java deleted file mode 100644 index 40c143a..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/interpreter/ShellTabGroup.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.interpreter; - -import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup; -import org.eclipse.debug.ui.ILaunchConfigurationDialog; -import org.eclipse.debug.ui.ILaunchConfigurationTab; -import org.eclipse.dltk.debug.ui.launchConfigurations.MainLaunchConfigurationTab; -import org.eclipse.dltk.debug.ui.launchConfigurations.ScriptArgumentsTab; -import org.eclipse.dltk.debug.ui.launchConfigurations.ScriptCommonTab; - -public class ShellTabGroup extends AbstractLaunchConfigurationTabGroup { - @Override - public void createTabs(ILaunchConfigurationDialog dialog, String mode) { - MainLaunchConfigurationTab main = new ShellMainLaunchConfigurationTab(mode); - ScriptArgumentsTab args = new ScriptArgumentsTab(); - ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { main, args, new ScriptCommonTab(main) }; - setTabs(tabs); - } -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/PreviewFile.txt b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/PreviewFile.txt deleted file mode 100644 index 7d36825..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/PreviewFile.txt +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -if [ -z $VARIABLE ] ; then - echo "double quoted text" # some comment - echo 'single quoted text' # TODO tag - echo `command substitution` -fi \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/ShellColoringConfigurationBlock.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/ShellColoringConfigurationBlock.java deleted file mode 100644 index ed85e0d..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/ShellColoringConfigurationBlock.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.preferences; - -import java.io.InputStream; - -import org.eclipse.dltk.internal.ui.editor.ScriptSourceViewer; -import org.eclipse.dltk.sh.ui.Activator; -import org.eclipse.dltk.sh.ui.IShellColorConstants; -import org.eclipse.dltk.sh.ui.editor.ShellDocumentSetupParticipant; -import org.eclipse.dltk.sh.ui.text.IShellPartitions; -import org.eclipse.dltk.ui.preferences.AbstractScriptEditorColoringConfigurationBlock; -import org.eclipse.dltk.ui.preferences.OverlayPreferenceStore; -import org.eclipse.dltk.ui.text.IColorManager; -import org.eclipse.dltk.ui.text.ScriptSourceViewerConfiguration; -import org.eclipse.dltk.ui.text.ScriptTextTools; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.source.IOverviewRuler; -import org.eclipse.jface.text.source.IVerticalRuler; -import org.eclipse.jface.text.source.projection.ProjectionViewer; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.texteditor.ITextEditor; - -public class ShellColoringConfigurationBlock extends AbstractScriptEditorColoringConfigurationBlock { - - private static final String PREVIEW_FILE_NAME = "PreviewFile.txt"; //$NON-NLS-1$ - - private static final String[][] fSyntaxColorListModel = new String[][] { - { "Comments", IShellColorConstants.SHELL_COMMENT, sCommentsCategory }, - { "Hashbang", IShellColorConstants.SHELL_HASHBANG, sCommentsCategory }, - { "TODO tags", IShellColorConstants.SHELL_TODO_TAG, sCommentsCategory }, - - { "Eval", IShellColorConstants.SHELL_EVAL, sCoreCategory }, - { "Double quoted text", IShellColorConstants.SHELL_DOUBLE_QUOTE, sCoreCategory }, - { "Function", IShellColorConstants.SHELL_FUNCTION, sCoreCategory }, - - { "Keyword", IShellColorConstants.SHELL_KEYWORD, sCoreCategory }, - - { "Single quoted text", IShellColorConstants.SHELL_SINGLE_QUOTE, sCoreCategory }, - { "Variables", IShellColorConstants.SHELL_VARIABLE, sCoreCategory }, - { "Commands", IShellColorConstants.SHELL_COMMAND, sCoreCategory }, - { "Default", IShellColorConstants.SHELL_DEFAULT, sCoreCategory } - - }; - - public ShellColoringConfigurationBlock(OverlayPreferenceStore store) { - super(store); - } - - @Override - protected String[][] getSyntaxColorListModel() { - return fSyntaxColorListModel; - } - - @Override - protected ProjectionViewer createPreviewViewer(Composite parent, IVerticalRuler verticalRuler, - IOverviewRuler overviewRuler, boolean showAnnotationsOverview, int styles, IPreferenceStore store) { - return new ScriptSourceViewer(parent, verticalRuler, overviewRuler, showAnnotationsOverview, styles, store); - } - - @Override - protected ScriptSourceViewerConfiguration createSimpleSourceViewerConfiguration(IColorManager colorManager, - IPreferenceStore preferenceStore, ITextEditor editor, boolean configureFormatter) { - return new SimpleShellSourceViewerConfiguration(colorManager, preferenceStore, editor, - IShellPartitions.SHELL_PARTITIONING, true); - } - - @Override - protected void setDocumentPartitioning(IDocument document) { - ShellDocumentSetupParticipant participant = new ShellDocumentSetupParticipant(); - participant.setup(document); - } - - @Override - protected InputStream getPreviewContentReader() { - return getClass().getResourceAsStream(PREVIEW_FILE_NAME); - } - - @Override - protected ScriptTextTools getTextTools() { - return Activator.getDefault().getTextTools(); - } -} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/ShellEditorPreferencesPage.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/ShellEditorPreferencesPage.java deleted file mode 100644 index 38ac9b3..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/ShellEditorPreferencesPage.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.preferences; - -import org.eclipse.dltk.sh.ui.Activator; -import org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPreferencePage; -import org.eclipse.dltk.ui.preferences.EditorConfigurationBlock; -import org.eclipse.dltk.ui.preferences.IPreferenceConfigurationBlock; -import org.eclipse.dltk.ui.preferences.OverlayPreferenceStore; - -public class ShellEditorPreferencesPage extends AbstractConfigurationBlockPreferencePage { - - @Override - protected String getHelpId() { - return null; - } - - @Override - protected void setDescription() { - setDescription("Shell Script Editor preferences"); - } - - @Override - protected void setPreferenceStore() { - setPreferenceStore(Activator.getDefault().getPreferenceStore()); - } - - @Override - protected IPreferenceConfigurationBlock createConfigurationBlock(OverlayPreferenceStore overlayPreferenceStore) { - return new EditorConfigurationBlock(this, overlayPreferenceStore); - } -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/ShellFoldingPreferencePage.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/ShellFoldingPreferencePage.java deleted file mode 100644 index 09f48d1..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/ShellFoldingPreferencePage.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Peter Palaga - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.preferences; - -import org.eclipse.dltk.sh.ui.Activator; -import org.eclipse.dltk.sh.ui.text.folding.ShellCodeFoldingPreferenceBlock; -import org.eclipse.dltk.sh.ui.text.folding.ShellCommentFoldingPreferenceBlock; -import org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPreferencePage; -import org.eclipse.dltk.ui.preferences.IPreferenceConfigurationBlock; -import org.eclipse.dltk.ui.preferences.OverlayPreferenceStore; -import org.eclipse.dltk.ui.text.folding.DefaultFoldingPreferenceConfigurationBlock; -import org.eclipse.dltk.ui.text.folding.IFoldingPreferenceBlock; -import org.eclipse.jface.preference.PreferencePage; - -/** - * A couple of usual folding options. - */ -public class ShellFoldingPreferencePage extends AbstractConfigurationBlockPreferencePage { - @Override - protected String getHelpId() { - return null; - } - - @Override - protected void setDescription() { - } - - @Override - protected void setPreferenceStore() { - setPreferenceStore(Activator.getDefault().getPreferenceStore()); - } - - @Override - protected IPreferenceConfigurationBlock createConfigurationBlock(OverlayPreferenceStore overlayPreferenceStore) { - return new DefaultFoldingPreferenceConfigurationBlock(overlayPreferenceStore, this) { - @Override - protected IFoldingPreferenceBlock createDocumentationBlock(OverlayPreferenceStore store, - PreferencePage page) { - return new ShellCommentFoldingPreferenceBlock(store, page); - } - - @Override - protected IFoldingPreferenceBlock createSourceCodeBlock(OverlayPreferenceStore store, PreferencePage page) { - return new ShellCodeFoldingPreferenceBlock(store, page); - } - }; - } -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/ShellSyntaxColoringPreferencePage.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/ShellSyntaxColoringPreferencePage.java deleted file mode 100644 index f002923..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/ShellSyntaxColoringPreferencePage.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.preferences; - -import org.eclipse.dltk.sh.ui.Activator; -import org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPreferencePage; -import org.eclipse.dltk.ui.preferences.IPreferenceConfigurationBlock; -import org.eclipse.dltk.ui.preferences.OverlayPreferenceStore; - -public class ShellSyntaxColoringPreferencePage extends AbstractConfigurationBlockPreferencePage { - - @Override - protected String getHelpId() { - return null; - } - - @Override - protected void setDescription() { - // leave blank - } - - @Override - protected void setPreferenceStore() { - setPreferenceStore(Activator.getDefault().getPreferenceStore()); - } - - @Override - protected IPreferenceConfigurationBlock createConfigurationBlock(OverlayPreferenceStore overlayPreferenceStore) { - return new ShellColoringConfigurationBlock(overlayPreferenceStore); - } -} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/ShellTodoTaskPreferencePage.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/ShellTodoTaskPreferencePage.java deleted file mode 100644 index fc0b3d0..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/ShellTodoTaskPreferencePage.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.preferences; - -import org.eclipse.core.resources.IProject; -import org.eclipse.dltk.sh.core.ShelledNature; -import org.eclipse.dltk.sh.ui.Activator; -import org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage; -import org.eclipse.dltk.ui.preferences.AbstractOptionsBlock; -import org.eclipse.dltk.ui.preferences.TodoTaskOptionsBlock; -import org.eclipse.dltk.ui.util.IStatusChangeListener; -import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; - -public class ShellTodoTaskPreferencePage extends AbstractConfigurationBlockPropertyAndPreferencePage { - - @Override - protected String getHelpId() { - return null; - } - - @Override - protected void setDescription() { - setDescription("Strings indicating tasks in Shell Script comments."); - } - - @Override - protected AbstractOptionsBlock createOptionsBlock(IStatusChangeListener newStatusChangedListener, IProject project, - IWorkbenchPreferenceContainer container) { - return new TodoTaskOptionsBlock(newStatusChangedListener, project, container, Activator.PLUGIN_ID); - } - - @Override - protected String getNatureId() { - return ShelledNature.SHELLED_NATURE; - } - - @Override - protected String getProjectHelpId() { - return null; - } - - @Override - protected void setPreferenceStore() { - setPreferenceStore(Activator.getDefault().getPreferenceStore()); - } - - @Override - protected String getPreferencePageId() { - return "org.eclipse.dltk.sh.todo"; - } - - @Override - protected String getPropertyPageId() { - return "org.eclipse.dltk.sh.todo"; - } - -} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/SimpleShellSourceViewerConfiguration.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/SimpleShellSourceViewerConfiguration.java deleted file mode 100644 index 2a7ed23..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/preferences/SimpleShellSourceViewerConfiguration.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.preferences; - -import org.eclipse.dltk.sh.ui.editor.ShellSourceViewerConfiguration; -import org.eclipse.dltk.ui.text.IColorManager; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.IAutoEditStrategy; -import org.eclipse.jface.text.IInformationControlCreator; -import org.eclipse.jface.text.ITextHover; -import org.eclipse.jface.text.formatter.IContentFormatter; -import org.eclipse.jface.text.hyperlink.IHyperlinkDetector; -import org.eclipse.jface.text.information.IInformationPresenter; -import org.eclipse.jface.text.source.IAnnotationHover; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.ui.texteditor.ITextEditor; - -public class SimpleShellSourceViewerConfiguration extends ShellSourceViewerConfiguration { - - private final boolean changeFormatter; - - public SimpleShellSourceViewerConfiguration(IColorManager colorManager, IPreferenceStore preferenceStore, - ITextEditor editor, String partitioning, boolean changeFormatter) { - super(colorManager, preferenceStore, editor, partitioning); - this.changeFormatter = changeFormatter; - } - - @Override - public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) { - return null; - } - - @Override - public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) { - return null; - } - - @Override - public IAnnotationHover getOverviewRulerAnnotationHover(ISourceViewer sourceViewer) { - return null; - } - - @Override - public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer, String contentType) { - return null; - } - - @Override - public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) { - return null; - } - - @Override - public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) { - return null; - } - - @Override - public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) { - if (changeFormatter) { - return super.getContentFormatter(sourceViewer); - } - return null; - } - - @Override - public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) { - return null; - } - - @Override - public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) { - return null; - } - - @Override - public IInformationPresenter getOutlinePresenter(ISourceViewer sourceViewer, boolean doCodeResolve) { - return null; - } - - @Override - public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) { - return null; - } -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/search/ShelledMatchLocationParser.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/search/ShelledMatchLocationParser.java deleted file mode 100644 index a588608..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/search/ShelledMatchLocationParser.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.search; - -import org.eclipse.dltk.ast.ASTNode; -import org.eclipse.dltk.core.search.matching.MatchLocator; -import org.eclipse.dltk.core.search.matching.MatchLocatorParser; -import org.eclipse.dltk.core.search.matching.PatternLocator; - -public class ShelledMatchLocationParser extends MatchLocatorParser { - protected ShelledMatchLocationParser(MatchLocator locator) { - super(locator); - } - - @Override - protected void processStatement(ASTNode node, PatternLocator locator) { - super.processStatement(node, locator); - } -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/search/ShelledSearchFactory.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/search/ShelledSearchFactory.java deleted file mode 100644 index d3ebf07..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/search/ShelledSearchFactory.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.search; - -import org.eclipse.dltk.core.search.AbstractSearchFactory; -import org.eclipse.dltk.core.search.IMatchLocatorParser; -import org.eclipse.dltk.core.search.matching.MatchLocator; - -public class ShelledSearchFactory extends AbstractSearchFactory { - @Override - public IMatchLocatorParser createMatchParser(MatchLocator locator) { - return new ShelledMatchLocationParser(locator); - } -} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/search/ShelledSearchPage.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/search/ShelledSearchPage.java deleted file mode 100644 index 66a4364..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/search/ShelledSearchPage.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.search; - -import org.eclipse.dltk.core.IDLTKLanguageToolkit; -import org.eclipse.dltk.sh.core.ShellScriptLanguageToolkit; -import org.eclipse.dltk.ui.search.ScriptSearchPage; - -public class ShelledSearchPage extends ScriptSearchPage { - @Override - protected IDLTKLanguageToolkit getLanguageToolkit() { - return ShellScriptLanguageToolkit.getDefault(); - } -} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/selection/ShellDocumentationProvider.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/selection/ShellDocumentationProvider.java deleted file mode 100644 index 5d72ea4..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/selection/ShellDocumentationProvider.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.selection; - -import java.io.Reader; -import java.io.StringReader; - -import org.eclipse.dltk.core.IMember; -import org.eclipse.dltk.ui.documentation.IScriptDocumentationProvider; -import org.eclipse.linuxtools.man.parser.ManPage; - -public class ShellDocumentationProvider implements IScriptDocumentationProvider { - - @Override - public Reader getInfo(String content) { - return new StringReader(new ManPage(content).getStrippedHtmlPage().toString()); - } - - @Override - public Reader getInfo(IMember element, boolean lookIntoParents, boolean lookIntoExternal) { - // TODO show comments for functions if there is any - return null; - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/selection/ShelledSelectionEngine.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/selection/ShelledSelectionEngine.java deleted file mode 100644 index d57c2be..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/selection/ShelledSelectionEngine.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.selection; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.dltk.ast.ASTVisitor; -import org.eclipse.dltk.ast.declarations.MethodDeclaration; -import org.eclipse.dltk.ast.declarations.ModuleDeclaration; -import org.eclipse.dltk.ast.expressions.Expression; -import org.eclipse.dltk.ast.expressions.MethodCallExpression; -import org.eclipse.dltk.ast.references.VariableReference; -import org.eclipse.dltk.codeassist.ScriptSelectionEngine; -import org.eclipse.dltk.compiler.env.IModuleSource; -import org.eclipse.dltk.core.DLTKCore; -import org.eclipse.dltk.core.IModelElement; -import org.eclipse.dltk.core.IModelElementVisitor; -import org.eclipse.dltk.core.ISourceModule; -import org.eclipse.dltk.core.ModelException; -import org.eclipse.dltk.core.SourceParserUtil; - -public class ShelledSelectionEngine extends ScriptSelectionEngine { - private ISourceModule sourceModule; - - @Override - public IModelElement[] select(IModuleSource module, final int offset, int i) { - sourceModule = (ISourceModule) module.getModelElement(); - ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(sourceModule, null); - final List results = new ArrayList<>(); - try { - moduleDeclaration.traverse(new ASTVisitor() { - @Override - public boolean visit(Expression s) throws Exception { - if ((s.sourceStart() <= offset) && (offset <= s.sourceEnd())) { - if (s instanceof MethodCallExpression) { - findDeclaration(((MethodCallExpression) s).getName(), results); - } - if (s instanceof VariableReference) { - findDeclaration(((VariableReference) s).getName(), results); - } - } - return super.visit(s); - } - - @Override - public boolean visit(MethodDeclaration s) throws Exception { - if ((s.getNameStart() <= offset) && (offset <= s.getNameEnd())) { - findDeclaration(s.getName(), results); - } - return super.visit(s); - } - - }); - } catch (Exception e) { - if (DLTKCore.DEBUG) { - e.printStackTrace(); - } - } - return results.toArray(new IModelElement[results.size()]); - } - - private void findDeclaration(final String name, final List results) { - try { - this.sourceModule.accept(new IModelElementVisitor() { - @Override - public boolean visit(IModelElement element) { - if (element.getElementName().equals(name)) { - results.add(element); - } - return true; - } - }); - } catch (ModelException e) { - if (DLTKCore.DEBUG) { - e.printStackTrace(); - } - } - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/AssignmentDetector.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/AssignmentDetector.java deleted file mode 100644 index 0eb5427..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/AssignmentDetector.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Mat Booth and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Mat Booth - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text; - -import org.eclipse.jface.text.rules.IWordDetector; - -/** - * Determines whether given any given character forms part of a shell - * assignment. - */ -public class AssignmentDetector implements IWordDetector { - - @Override - public boolean isWordPart(char c) { - return Character.isJavaIdentifierPart(c) || (c == '[') || (c == ']'); - } - - @Override - public boolean isWordStart(char c) { - return Character.isJavaIdentifierStart(c); - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/AssignmentRule.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/AssignmentRule.java deleted file mode 100644 index 8b68866..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/AssignmentRule.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text; - -import org.eclipse.jface.text.rules.ICharacterScanner; -import org.eclipse.jface.text.rules.IRule; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.IWordDetector; -import org.eclipse.jface.text.rules.Token; - -public class AssignmentRule implements IRule { - private final StringBuffer buffer = new StringBuffer(); - private final IToken defaultToken; - private final IWordDetector detector; - private final IToken successToken; - - public AssignmentRule(IWordDetector detector, IToken defaultToken, IToken token) { - this.detector = detector; - this.successToken = token; - this.defaultToken = defaultToken; - } - - @Override - public IToken evaluate(ICharacterScanner scanner) { - char c = (char) scanner.read(); - if (detector.isWordStart((c))) { - buffer.setLength(0); - do { - buffer.append((c)); - c = (char) scanner.read(); - } while ((c != ICharacterScanner.EOF) && detector.isWordPart(c)); - scanner.unread(); - if (c == '=') { - return successToken; - } - if (defaultToken.isUndefined()) { - unreadBuffer(scanner); - } - return defaultToken; - } - scanner.unread(); - return Token.UNDEFINED; - } - - /** - * Returns the characters in the buffer to the scanner. - * - * @param scanner - * the scanner to be used - */ - protected void unreadBuffer(ICharacterScanner scanner) { - for (int i = buffer.length() - 1; i >= 0; i--) { - scanner.unread(); - } - } -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/DocumentAndCommandScanner.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/DocumentAndCommandScanner.java deleted file mode 100644 index d860d61..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/DocumentAndCommandScanner.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.DocumentCommand; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.rules.RuleBasedScanner; - -/** - * This scanner extends the normal rule based scanner by adding the ability to - * read DocumentCommands as well as IDocuments. This ability is toggled on or - * off depending on whether setRange(document,offset,length) (off) or - * setRange(document,documentCommand,offset,length) (on) was called. - * - * @author Doug Satchwell - * @version $Id: DocumentAndCommandScanner.java,v 1.2 2008/12/02 21:59:55 - * akurtakov Exp $ - */ -public class DocumentAndCommandScanner extends RuleBasedScanner { - private DocumentCommand fDocumentCommand; - - @Override - public int read() { - try { - if (fOffset < fRangeEnd) { - try { - return fDocument.getChar(fOffset); - } catch (BadLocationException e) { - } - } - if ((fDocumentCommand != null) && (fOffset < (fRangeEnd + fDocumentCommand.text.length()))) { - return fDocumentCommand.text.charAt(((fRangeEnd + fDocumentCommand.text.length()) - fOffset) - 1); - } - return EOF; - } finally { - ++fOffset; - } - } - - /** - * Set this to use as a normal in conjunction with DocumentCommand's - */ - public void setRange(IDocument document, DocumentCommand documentCommand, int offset, int length) { - setRange(document, offset, length); - fDocumentCommand = documentCommand; - } - - /** - * Set this to use as a normal RuleBasedScanner - */ - @Override - public void setRange(IDocument document, int offset, int length) { - super.setRange(document, offset, length); - fDocumentCommand = null; - } -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/DollarBraceCountingRule.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/DollarBraceCountingRule.java deleted file mode 100644 index b7bf20c..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/DollarBraceCountingRule.java +++ /dev/null @@ -1,124 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Mat Booth and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text; - -import org.eclipse.jface.text.rules.ICharacterScanner; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.PatternRule; - -/** - * This rule captures a pattern that begins with '$' and an opening brace and - * ends with a closed brace. This is used for highlighting ${} or $() blocks. It - * counts the opening and closing braces as it encounters them to make sure we - * always end at the correct closing brace or the end of the line, which ever - * comes first. - */ -public class DollarBraceCountingRule extends PatternRule { - - private char[][] fLineDelimiters; - private char[][] fSortedLineDelimiters; - - private final char fOpening; - private final char fClosing; - - /** - * Creates a rule for the given opening and closing braces. When these - * braces are detected the rule will return the specified token. - * Alternatively, the sequence can also be ended by the end of the line. Any - * character which follows the given escapeCharacter will be ignored. - * - * @param openingBrace - * the pattern's start sequence - * @param closingBrace - * the pattern's end sequence, null is a legal value - * @param token - * the token which will be returned on success - * @param escapeChar - * any character following this one will be ignored - */ - public DollarBraceCountingRule(char openingBrace, char closingBrace, IToken token, char escapeChar) { - super("$" + Character.toString(openingBrace), Character.toString(closingBrace), token, escapeChar, true, false, - false); - fOpening = openingBrace; - fClosing = closingBrace; - } - - /** - * This method is rather more or less identical to the super class - * implementation with the exception that instead of checking for the end - * sequence, it counts occurrences of braces and returns successfully when - * the number of closing braces encountered equals the number of opening - * braces. - * - * @see org.eclipse.jface.text.rules.PatternRule#endSequenceDetected(org.eclipse.jface.text.rules.ICharacterScanner) - */ - @Override - protected boolean endSequenceDetected(ICharacterScanner scanner) { - char[][] originalDelimiters = scanner.getLegalLineDelimiters(); - int count = originalDelimiters.length; - if ((fLineDelimiters == null) || (originalDelimiters.length != count)) { - fSortedLineDelimiters = new char[count][]; - } else { - while ((count > 0) && (fLineDelimiters[count - 1] == originalDelimiters[count - 1])) { - count--; - } - } - if (count != 0) { - fLineDelimiters = originalDelimiters; - System.arraycopy(fLineDelimiters, 0, fSortedLineDelimiters, 0, fLineDelimiters.length); - } - - int readCount = 1; - int c; - int fBraceCount = 1; - while ((c = scanner.read()) != ICharacterScanner.EOF) { - if (c == fEscapeCharacter) { - // Skip escaped character(s) - if (fEscapeContinuesLine) { - c = scanner.read(); - for (char[] fSortedLineDelimiter : fSortedLineDelimiters) { - if ((c == fSortedLineDelimiter[0]) && sequenceDetected(scanner, fSortedLineDelimiter, true)) { - break; - } - } - } else - scanner.read(); - - } else if (c == fOpening) { - // Count opening braces - fBraceCount++; - } else if (c == fClosing) { - // Count closing braces - fBraceCount--; - // End successfully when the open brace count returns to zero - if (fBraceCount == 0) { - return true; - } - } else if (fBreaksOnEOL) { - // Check for end of line since it can be used to terminate the - // pattern. - for (char[] fSortedLineDelimiter : fSortedLineDelimiters) { - if ((c == fSortedLineDelimiter[0]) && sequenceDetected(scanner, fSortedLineDelimiter, true)) { - return true; - } - } - } - readCount++; - } - - if (fBreaksOnEOF) { - return true; - } - - for (; readCount > 0; readCount--) { - scanner.unread(); - } - - return false; - } -} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/DollarDetector.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/DollarDetector.java deleted file mode 100644 index fcb8199..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/DollarDetector.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text; - -import org.eclipse.jface.text.rules.IWordDetector; - -/** - * Determines whether given any given character forms part of a shell variable. - */ -public class DollarDetector implements IWordDetector { - - @Override - public boolean isWordPart(char c) { - return Character.isJavaIdentifierPart(c); - } - - @Override - public boolean isWordStart(char c) { - return c == '$'; - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/DollarRule.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/DollarRule.java deleted file mode 100644 index 5dada48..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/DollarRule.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text; - -import org.eclipse.jface.text.rules.ICharacterScanner; -import org.eclipse.jface.text.rules.IRule; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.IWordDetector; -import org.eclipse.jface.text.rules.Token; - -/** - * This rule captures parameter expansions that are not covered by - * DollarBraceCountingRule. That is, all dollar-prefixed variables including - * special variables where encapsulation in braces is not necessary. - */ -public class DollarRule implements IRule { - - private final StringBuffer buffer = new StringBuffer(); - private final IToken defaultToken; - private final IWordDetector detector; - private final IToken successToken; - - public DollarRule(IWordDetector detector, IToken defaultToken, IToken token) { - this.detector = detector; - this.successToken = token; - this.defaultToken = defaultToken; - } - - /** - * Returns whether the specified character is a special parameter in shell - * script. A dollar sign combined with any of the following characters will - * be highlighted, but no characters after that. - *

- * '*', '@' - positional parameters starting from 1
- * '#' - number of positional parameters
- * '?' - exit status of the last executed foreground command
- * '-' - current option flags
- * '$' - PID of the shell
- * '!' - PID of the last executed background command
- * '_' - pathname used to invoke the shell and every subsequent command
- * '0' - usually the name of the file used to invoke the shell
- * '1' to '9' - expands to the corresponding positional parameters, - * parameters 10+ must be referenced with braces like ${12} - * - * @param c - * a character to test - * @return true if the specified character is a special parameter - */ - private static boolean isSpecial(char c) { - return ((c == '*') || (c == '@') || (c == '#') || (c == '?') || (c == '-') || (c == '$') || (c == '!') - || (c == '_') || Character.isDigit(c)); - } - - @Override - public IToken evaluate(ICharacterScanner scanner) { - int c = scanner.read(); - if (detector.isWordStart((char) c)) { - buffer.setLength(0); - do { - buffer.append((char) c); - c = scanner.read(); - if ((buffer.length() == 1) && isSpecial((char) c)) { - return successToken; - } - } while ((c != ICharacterScanner.EOF) && detector.isWordPart((char) c)); - scanner.unread(); - if (buffer.length() > 1) { - return successToken; - } - if (defaultToken.isUndefined()) { - unreadBuffer(scanner); - } - return defaultToken; - } - scanner.unread(); - return Token.UNDEFINED; - } - - /** - * Returns the characters in the buffer to the scanner. - * - * @param scanner - * the scanner to be used - */ - protected void unreadBuffer(ICharacterScanner scanner) { - for (int i = buffer.length() - 1; i >= 0; i--) { - scanner.unread(); - } - } -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/DoubleQuoteScanner.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/DoubleQuoteScanner.java deleted file mode 100644 index ff3a90c..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/DoubleQuoteScanner.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009-2010 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.dltk.sh.ui.IShellColorConstants; -import org.eclipse.dltk.ui.text.AbstractScriptScanner; -import org.eclipse.dltk.ui.text.IColorManager; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.rules.IRule; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.SingleLineRule; -import org.eclipse.jface.text.rules.WhitespaceRule; - -/** - * Scans interpolated string partitions of documents. I.e., the sections between - * double quote marks. - */ -public class DoubleQuoteScanner extends AbstractScriptScanner { - - /** - * Array of preference keys used to define the style of token types used by - * this scanner. - */ - private static String fgTokenProperties[] = new String[] { IShellColorConstants.SHELL_EVAL, - IShellColorConstants.SHELL_DOUBLE_QUOTE, IShellColorConstants.SHELL_VARIABLE }; - - public DoubleQuoteScanner(IColorManager manager, IPreferenceStore store) { - super(manager, store); - initialize(); - } - - @Override - protected List createRules() { - List rules = new ArrayList<>(); - - // Token types used in the rules - IToken defaultToken = this.getToken(IShellColorConstants.SHELL_DOUBLE_QUOTE); - IToken evalToken = this.getToken(IShellColorConstants.SHELL_EVAL); - IToken varToken = this.getToken(IShellColorConstants.SHELL_VARIABLE); - - // Add generic whitespace rule. This is here for efficiency reasons, - // there is a LOT of whitespace and when a token is detected the other - // rules are not evaluated. - rules.add(new WhitespaceRule(new WhitespaceDetector())); - rules.add(new DollarBraceCountingRule('(', ')', evalToken, '\\')); - rules.add(new DollarBraceCountingRule('{', '}', varToken, '\\')); - rules.add(new DollarRule(new DollarDetector(), defaultToken, varToken)); - rules.add(new SingleLineRule("`", "`", evalToken, '\\', false)); - setDefaultReturnToken(defaultToken); - return rules; - } - - @Override - protected String[] getTokenProperties() { - return fgTokenProperties; - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/EvalScanner.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/EvalScanner.java deleted file mode 100644 index 53b28e5..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/EvalScanner.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Mat Booth and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.dltk.sh.ui.IShellColorConstants; -import org.eclipse.dltk.ui.text.AbstractScriptScanner; -import org.eclipse.dltk.ui.text.IColorManager; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.rules.IRule; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.WhitespaceRule; - -/** - * Scans command substitution document partitions. I.e., the sections between - * back-ticks or enclosed in $()s. - */ -public class EvalScanner extends AbstractScriptScanner { - - /** - * Array of preference keys used to define the style of token types used by - * this scanner. - */ - private static String fgTokenProperties[] = new String[] { IShellColorConstants.SHELL_EVAL, - IShellColorConstants.SHELL_VARIABLE }; - - public EvalScanner(IColorManager manager, IPreferenceStore store) { - super(manager, store); - initialize(); - } - - @Override - protected List createRules() { - List rules = new ArrayList<>(); - - // Token types used in the rules - IToken defaultToken = this.getToken(IShellColorConstants.SHELL_EVAL); - IToken varToken = this.getToken(IShellColorConstants.SHELL_VARIABLE); - - // Add generic whitespace rule. This is here for efficiency reasons, - // there is a LOT of whitespace and when a token is detected the other - // rules are not evaluated. - rules.add(new WhitespaceRule(new WhitespaceDetector())); - rules.add(new DollarBraceCountingRule('{', '}', varToken, '\\')); - rules.add(new DollarRule(new DollarDetector(), defaultToken, varToken)); - setDefaultReturnToken(defaultToken); - return rules; - } - - @Override - protected String[] getTokenProperties() { - return fgTokenProperties; - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/IShellPartitions.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/IShellPartitions.java deleted file mode 100644 index a27fe50..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/IShellPartitions.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text; - -import org.eclipse.jface.text.IDocument; - -public interface IShellPartitions { - String SHELL_PARTITIONING = "__shell_partitioning"; - - // Content types supplied by the shell script partitioner - String COMMENT_CONTENT_TYPE = "__comment"; - String DOUBLE_QUOTE_CONTENT_TYPE = "__double_quote"; - String PARAM_CONTENT_TYPE = "__parameter"; - String EVAL_CONTENT_TYPE = "__eval"; - String HASHBANG_CONTENT_TYPE = "__hashbang"; - String FUNCTION_CONTENT_TYPE = "__function"; - String SINGLE_QUOTE_CONTENT_TYPE = "__single_quote"; - - String[] CONTENT_TYPES = new String[] { IDocument.DEFAULT_CONTENT_TYPE, HASHBANG_CONTENT_TYPE, COMMENT_CONTENT_TYPE, - SINGLE_QUOTE_CONTENT_TYPE, DOUBLE_QUOTE_CONTENT_TYPE, PARAM_CONTENT_TYPE, EVAL_CONTENT_TYPE, - FUNCTION_CONTENT_TYPE }; -} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/IndentType.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/IndentType.java deleted file mode 100644 index cd9a117..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/IndentType.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text; - -/** - * A type of indent. - */ -public final class IndentType { - /** A single indent decrement */ - public static final IndentType DECREMENT = new IndentType(); - /** A single indent increment */ - public static final IndentType INCREMENT = new IndentType(); - /** An inflexion - both an increment and a decrement */ - public static final IndentType INFLEXION = new IndentType(); - - private IndentType() { - } -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/ScriptAutoIndentStrategy.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/ScriptAutoIndentStrategy.java deleted file mode 100644 index da30b87..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/ScriptAutoIndentStrategy.java +++ /dev/null @@ -1,346 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - * Mat Booth - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text; - -import org.eclipse.dltk.sh.ui.Activator; -import org.eclipse.dltk.ui.CodeFormatterConstants; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.DocumentCommand; -import org.eclipse.jface.text.IAutoEditStrategy; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.TextUtilities; -import org.eclipse.jface.text.rules.IRule; -import org.eclipse.jface.text.rules.IToken; - -/** - * An indent strategy capable of indenting and unindenting on any set of words, - * depending on the rules that are set. - * - * @see #setRules(IRule[]) - */ -public class ScriptAutoIndentStrategy implements IAutoEditStrategy { - /** - * Document scanner used to identify indentations. - */ - private final DocumentAndCommandScanner scanner = new DocumentAndCommandScanner(); - - /** - * Set the rules that will be used in a document scanner to identify where - * indentations should occur. Typically you'd have one rule to describe each - * type of indentation. - * - * @param rules - * the list of rules - * @see IndentType - */ - public void setRules(IRule[] rules) { - scanner.setRules(rules); - } - - /** - * This implementation attempts to auto-indent and auto-unindent after - * keywords that require it. - */ - @Override - public void customizeDocumentCommand(IDocument d, DocumentCommand c) { - int delim = TextUtilities.endsWith(d.getLegalLineDelimiters(), c.text); - if ((c.length == 0) && (c.text != null) && (delim != -1)) { - smartIndentAfterNewLine(d, c); - } else if (c.text.length() == 1) { - smartIndentAfterKeypress(d, c); - } - } - - /** - * Set the indent of a new line when the user hits carriage return. The new - * indent will either be the same as the previous line or incremented if the - * user has hit carriage return on a line that contains a incrementing - * keyword. - * - * @param document - * the document being parsed - * @param c - * the command being performed - */ - protected void smartIndentAfterNewLine(IDocument document, DocumentCommand c) { - if ((c.offset == -1) || (document.getLength() == 0)) { - return; - } - try { - StringBuffer buf = new StringBuffer(c.text); - int p = c.offset == document.getLength() ? c.offset - 1 : c.offset; - int line = document.getLineOfOffset(p); - int start = document.getLineOffset(line); - int bracketCount = getBracketCount(document, null, start, c.offset, true); - buf.append(generateIndentation(getIndentOfLine(document, line), bracketCount <= 0 ? 0 : 1)); - c.text = buf.toString(); - } catch (BadLocationException x) { - x.printStackTrace(); - } - } - - /** - * Set the indent of the current line when the user hits a key. The indent - * will either be unchanged or decremented if the user types - * - * @param document - * the document being parsed - * @param c - * the command being performed - */ - protected void smartIndentAfterKeypress(IDocument document, DocumentCommand c) { - if ((c.offset == -1) || (document.getLength() == 0)) { - return; - } - try { - StringBuffer buf = new StringBuffer(); - int p = c.offset == document.getLength() ? c.offset - 1 : c.offset; - int line = document.getLineOfOffset(p); - int start = document.getLineOffset(line); - int whiteEnd = findEndOfWhiteSpace(document, start, c.offset); - - int bracketCount = getBracketCount(document, c, start, c.offset, false); - buf.append(generateIndentation(getIndentOfLine(document, line), bracketCount >= 0 ? 0 : -1)); - buf.append(document.get(whiteEnd, c.offset - whiteEnd)); - buf.append(c.text); - // Alter the command - c.length = (c.offset - start) + c.length; - c.offset = start; - c.text = buf.toString(); - } catch (BadLocationException x) { - x.printStackTrace(); - } - } - - /** - * Returns the first offset greater than offset and smaller - * than end whose character is not a space or tab character. If - * no such offset is found, end is returned. - * - * @param document - * the document to search in - * @param offset - * the offset at which searching start - * @param end - * the offset at which searching stops - * @return the offset in the specified range whose character is not a space - * or tab - * @exception BadLocationException - * if offset is an invalid position in the given document - */ - private static int findEndOfWhiteSpace(IDocument document, int offset, int end) throws BadLocationException { - while (offset < end) { - char c = document.getChar(offset); - if ((c != ' ') && (c != '\t')) { - return offset; - } - offset++; - } - return end; - } - - /** - * Returns the indentation of the specified line in document. - * - * @param document - * - the document being parsed - * @param line - * - the line number being searched - * @return the string containing the indentation from the specified line - */ - private static String getIndentOfLine(IDocument document, int line) throws BadLocationException { - if (line > -1) { - int start = document.getLineOffset(line); - int end = start + document.getLineLength(line); - int whiteend = findEndOfWhiteSpace(document, start, end); - return document.get(start, whiteend - start); - } else { - return ""; - } - } - - /** - * Returns the bracket count of a section of text. The count is incremented - * when an opening bracket is encountered and decremented when a closing - * bracket is encountered. - * - * @param document - * - the document being parsed - * @param command - * - if not null, the inserted text specified by the command will - * be taken into account as if it were part of the document - * @param start - * - the start position for the search - * @param end - * - the end position for the search - * @param ignoreInflexions - * - whether or not to ignore inflexions in the count - * @return the resulting bracket count, a positive value means we've - * encountered more opening than closing brackets - */ - private int getBracketCount(IDocument document, DocumentCommand command, int start, int end, - boolean ignoreInflexions) { - int bracketcount = 0; - if (command != null) { - scanner.setRange(document, command, start, end - start); - } else { - scanner.setRange(document, start, end - start); - } - - while (true) { - IToken token = scanner.nextToken(); - if (token.isEOF()) { - break; - } - - if (token.isOther()) { - IndentType type = (IndentType) token.getData(); - if (type == IndentType.INCREMENT) { - ++bracketcount; - } else if (type == IndentType.DECREMENT) { - --bracketcount; - } else if ((type == IndentType.INFLEXION) && ignoreInflexions) { - ++bracketcount; - } else if ((type == IndentType.INFLEXION) && !ignoreInflexions) { - --bracketcount; - } - } - } - return bracketcount; - } - - /** - * Calculate the indentation needed for a new line based on the contents of - * the previous line. - * - * @param previous - * a string containing the indentation of the previous line - * @param additional - * number of desired addition indentations, may be negative - * @return a string containing the indentation to use on the new line - */ - private static String generateIndentation(String previous, int additional) { - // Get the indentation preferences - IPreferenceStore prefs = Activator.getDefault().getPreferenceStore(); - String tabChar = prefs.getString(CodeFormatterConstants.FORMATTER_TAB_CHAR); - int indentSize = prefs.getInt(CodeFormatterConstants.FORMATTER_INDENTATION_SIZE); - int tabSize = prefs.getInt(CodeFormatterConstants.FORMATTER_TAB_SIZE); - - // Size in characters of the indentation of the previous line - int preLength = computeVisualLength(previous, tabSize); - - // Number of addition characters needed - int addLength = indentSize * additional; - - // Target size of the indentation for the new line - int endLength = Math.max(0, preLength + addLength); - - // Trim previous indentation back to nearest tab stop - int minLength = Math.min(endLength, preLength); - int maxCopyLength = tabSize > 0 ? minLength - (minLength % tabSize) : minLength; // maximum - // indent - // to - // copy - String indent = stripExtraChars(previous, maxCopyLength, tabSize); - - // Add additional indentation - int missing = endLength - maxCopyLength; - final int tabs, spaces; - if (CodeFormatterConstants.SPACE.equals(tabChar)) { - // Each indent is a number of spaces equal to indent size - tabs = 0; - spaces = missing; - } else if (CodeFormatterConstants.TAB.equals(tabChar)) { - // Missing should always be in multiples of indent size, so this - // means "one tab per indent" and indent size is essentially ignored - tabs = missing / indentSize; - spaces = 0; - } else if (CodeFormatterConstants.MIXED.equals(tabChar)) { - // If the missing indent is a multiple of tab size then tabs will be - // used, otherwise use spaces - tabs = tabSize > 0 ? missing / tabSize : 0; - spaces = tabSize > 0 ? missing % tabSize : missing; - } else { - tabs = 0; - spaces = 0; - } - for (int i = 0; i < tabs; i++) { - indent += "\t"; - } - for (int i = 0; i < spaces; i++) { - indent += " "; - } - return indent; - } - - /** - * Computes the length of a an indentation, counting a tab character as the - * size until the next tab stop and every other character as one. - * - * @param indent - * the string containing the indentation to measure - * @param tabSize - * the visual size of tab characters - * @return the visual length in number of characters - */ - private static int computeVisualLength(String indent, int tabSize) { - int length = 0; - for (int i = 0; i < indent.length(); i++) { - char ch = indent.charAt(i); - switch (ch) { - case '\t': - if (tabSize > 0) { - int reminder = length % tabSize; - length += tabSize - reminder; - } - break; - case ' ': - length++; - break; - } - } - return length; - } - - /** - * Strips any characters off the end of an indentation that exceed a - * specified maximum visual indentation length. - * - * @param indent - * the string containing the indentation to measure - * @param max - * the maximum visual indentation length - * @param tabSize - * the visual size of tab characters - * @return a string containing the stripped indentation - */ - private static String stripExtraChars(String indent, int max, int tabSize) { - int measured = 0; - int i = 0; - for (; (measured < max) && (i < indent.length()); i++) { - char ch = indent.charAt(i); - switch (ch) { - case '\t': - if (tabSize > 0) { - int reminder = measured % tabSize; - measured += tabSize - reminder; - } - break; - case ' ': - measured++; - break; - } - } - return indent.substring(0, measured > max ? i - 1 : i); - } -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/ShellCodeScanner.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/ShellCodeScanner.java deleted file mode 100644 index 77cc5cf..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/ShellCodeScanner.java +++ /dev/null @@ -1,119 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009-2011 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - * Mat Booth - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.dltk.sh.ui.Activator; -import org.eclipse.dltk.sh.ui.IShellColorConstants; -import org.eclipse.dltk.ui.text.AbstractScriptScanner; -import org.eclipse.dltk.ui.text.IColorManager; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.rules.IRule; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.IWordDetector; -import org.eclipse.jface.text.rules.Token; -import org.eclipse.jface.text.rules.WhitespaceRule; -import org.eclipse.jface.text.rules.WordRule; - -public class ShellCodeScanner extends AbstractScriptScanner { - public static class ShellWordDetector implements IWordDetector { - @Override - public boolean isWordPart(char character) { - return (Character.isJavaIdentifierPart(character) && (character != '$')) || (character == '-') - || (character == '.'); - } - - @Override - public boolean isWordStart(char character) { - return Character.isJavaIdentifierStart(character) && (character != 36); - } - } - - public static final String[] KEYWORDS = { "do", "done", "if", "fi", "then", "else", "elif", "case", "esac", "while", - "for", "in", "select", "time", "until", "function", "[", "[[", "]", "]]", "set", "unset", "declare" }; - - private static List fgCommands = getCommands(); - - private static String fgTokenProperties[] = new String[] { IShellColorConstants.SHELL_DEFAULT, - IShellColorConstants.SHELL_KEYWORD, IShellColorConstants.SHELL_VARIABLE, - IShellColorConstants.SHELL_COMMAND }; - - public ShellCodeScanner(IColorManager manager, IPreferenceStore store) { - super(manager, store); - this.initialize(); - } - - public static List getCommands() { - String path = System.getenv("PATH"); - List commands = new ArrayList<>(); - String[] pathEntries = path.split(System.getProperty("path.separator")); - for (String pathEntry : pathEntries) { - File dir = new File(pathEntry); - if (dir.exists() && dir.isDirectory()) { - - File[] files = dir.listFiles(); - - // GRO: Prevent NullPointerException - if (files == null) { - // @formatter:off - Activator.getDefault().getLog().log(// + - new Status(IStatus.ERROR, Activator.PLUGIN_ID, "listFiles() returned null: " + dir)); - // @formatter:on - files = new File[] {}; - } - - for (File file : files) { - if (file.canExecute()) { - if (file.getName().endsWith(".exe")) { - commands.add(file.getName().substring(0, file.getName().length() - 4)); - } else { - commands.add(file.getName()); - } - } - } - } - } - return commands; - } - - @Override - protected List createRules() { - List rules = new ArrayList<>(); - IToken keyword = this.getToken(IShellColorConstants.SHELL_KEYWORD); - IToken commandToken = this.getToken(IShellColorConstants.SHELL_COMMAND); - IToken other = this.getToken(IShellColorConstants.SHELL_DEFAULT); - IToken variable = this.getToken(IShellColorConstants.SHELL_VARIABLE); - rules.add(new WhitespaceRule(new WhitespaceDetector())); - rules.add(new AssignmentRule(new AssignmentDetector(), Token.UNDEFINED, variable)); - rules.add(new DollarRule(new DollarDetector(), Token.UNDEFINED, variable)); - WordRule wordRule = new WordRule(new ShellWordDetector(), other); - for (String element : KEYWORDS) { - wordRule.addWord(element, keyword); - } - for (String command : fgCommands) { - wordRule.addWord(command, commandToken); - } - rules.add(wordRule); - return rules; - } - - @Override - protected String[] getTokenProperties() { - return fgTokenProperties; - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/ShellPartitionScanner.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/ShellPartitionScanner.java deleted file mode 100644 index d3be4aa..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/ShellPartitionScanner.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ - -package org.eclipse.dltk.sh.ui.text; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jface.text.rules.EndOfLineRule; -import org.eclipse.jface.text.rules.IPredicateRule; -import org.eclipse.jface.text.rules.IRule; -import org.eclipse.jface.text.rules.RuleBasedPartitionScanner; -import org.eclipse.jface.text.rules.SingleLineRule; -import org.eclipse.jface.text.rules.Token; - -public class ShellPartitionScanner extends RuleBasedPartitionScanner { - - public ShellPartitionScanner() { - super(); - - List rules = new ArrayList<>(); - // Add rule for single line comments. - rules.add(new EndOfLineRule("#!", new Token(IShellPartitions.HASHBANG_CONTENT_TYPE))); - /* - * There are 2 comment rules in order to correctly support # in - * variables. - */ - // This rule recognizes only comments starting from the beginning of - // line. - EndOfLineRule commentRule = new EndOfLineRule("#", new Token(IShellPartitions.COMMENT_CONTENT_TYPE)); - commentRule.setColumnConstraint(0); - rules.add(commentRule); - // This rule recognizes only comments which has space in front of it - commentRule = new EndOfLineRule(" #", new Token(IShellPartitions.COMMENT_CONTENT_TYPE)); - rules.add(commentRule); - commentRule = new EndOfLineRule("\t#", new Token(IShellPartitions.COMMENT_CONTENT_TYPE)); - rules.add(commentRule); - - rules.add(new DollarBraceCountingRule('(', ')', new Token(IShellPartitions.EVAL_CONTENT_TYPE), '\\')); - rules.add(new DollarBraceCountingRule('{', '}', new Token(IShellPartitions.PARAM_CONTENT_TYPE), '\\')); - rules.add(new SingleLineRule("`", "`", new Token(IShellPartitions.EVAL_CONTENT_TYPE), '\\', false, true)); - rules.add(new SingleLineRule("\"", "\"", new Token(IShellPartitions.DOUBLE_QUOTE_CONTENT_TYPE), '\\', false, - true)); - rules.add( - new SingleLineRule("'", "'", new Token(IShellPartitions.SINGLE_QUOTE_CONTENT_TYPE), '\\', false, true)); - - IPredicateRule[] result = new IPredicateRule[rules.size()]; - rules.toArray(result); - setPredicateRules(result); - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/ShellTextTools.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/ShellTextTools.java deleted file mode 100644 index 8419a82..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/ShellTextTools.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text; - -import org.eclipse.dltk.sh.ui.editor.ShellSourceViewerConfiguration; -import org.eclipse.dltk.ui.text.ScriptSourceViewerConfiguration; -import org.eclipse.dltk.ui.text.ScriptTextTools; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.rules.IPartitionTokenScanner; -import org.eclipse.ui.texteditor.ITextEditor; - -public class ShellTextTools extends ScriptTextTools { - - private final IPartitionTokenScanner fPartitionScanner; - - public ShellTextTools(boolean autoDisposeOnDisplayDispose) { - super(IShellPartitions.SHELL_PARTITIONING, IShellPartitions.CONTENT_TYPES, autoDisposeOnDisplayDispose); - fPartitionScanner = new ShellPartitionScanner(); - } - - @Override - public ScriptSourceViewerConfiguration createSourceViewerConfiguraton(IPreferenceStore preferenceStore, - ITextEditor editor, String partitioning) { - return new ShellSourceViewerConfiguration(getColorManager(), preferenceStore, editor, partitioning); - } - - @Override - public IPartitionTokenScanner createPartitionScanner() { - return fPartitionScanner; - } - -} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/WhitespaceDetector.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/WhitespaceDetector.java deleted file mode 100644 index b2b0ddf..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/WhitespaceDetector.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text; - -import org.eclipse.jface.text.rules.IWhitespaceDetector; - -public class WhitespaceDetector implements IWhitespaceDetector { - - @Override - public boolean isWhitespace(char c) { - return Character.isWhitespace(c); - } -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/folding/FoldingBlockKind.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/folding/FoldingBlockKind.java deleted file mode 100644 index 7807d2f..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/folding/FoldingBlockKind.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text.folding; - -import org.eclipse.dltk.ui.text.folding.IFoldingBlockKind; - -public enum FoldingBlockKind implements IFoldingBlockKind { - FUNCTION, COMMENT; - - @Override - public boolean isComment() { - return this == COMMENT; - } -} \ No newline at end of file diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/folding/ShellCodeFoldingBlockProvider.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/folding/ShellCodeFoldingBlockProvider.java deleted file mode 100644 index cd00441..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/folding/ShellCodeFoldingBlockProvider.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text.folding; - -import org.eclipse.dltk.core.IMethod; -import org.eclipse.dltk.core.IModelElement; -import org.eclipse.dltk.ui.PreferenceConstants; -import org.eclipse.dltk.ui.text.folding.IFoldingBlockKind; -import org.eclipse.dltk.ui.text.folding.ModelFoldingBlockProvider; -import org.eclipse.jface.preference.IPreferenceStore; - -public class ShellCodeFoldingBlockProvider extends ModelFoldingBlockProvider { - private int minimalLineCount; - private boolean foldingEnabled; - private boolean functionsCollapsedInitially; - - @Override - public boolean visit(IModelElement element) { - if (element instanceof IMethod) { - reportElement(element); - } - return true; - } - - @Override - public void initializePreferences(IPreferenceStore preferenceStore) { - super.initializePreferences(preferenceStore); - minimalLineCount = preferenceStore.getInt(PreferenceConstants.EDITOR_FOLDING_LINES_LIMIT); - foldingEnabled = preferenceStore.getBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED); - functionsCollapsedInitially = preferenceStore.getBoolean(PreferenceConstants.EDITOR_FOLDING_INIT_METHODS); - } - - @Override - public int getMinimalLineCount() { - return minimalLineCount; - } - - @Override - protected boolean isFoldedInitially(IModelElement element) { - if (foldingEnabled) { - if (element instanceof IMethod) { - return functionsCollapsedInitially; - } - } - return false; - } - - @Override - protected IFoldingBlockKind getKind(IModelElement element) { - if (element instanceof IMethod) { - return FoldingBlockKind.FUNCTION; - } - /* - * this should not happen. getKind() should be called for functions only - * because we reportElement() only for IMethod in visit() - */ - return null; - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/folding/ShellCodeFoldingPreferenceBlock.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/folding/ShellCodeFoldingPreferenceBlock.java deleted file mode 100644 index 0178fdb..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/folding/ShellCodeFoldingPreferenceBlock.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Peter Palaga - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text.folding; - -import org.eclipse.dltk.ui.preferences.OverlayPreferenceStore; -import org.eclipse.dltk.ui.text.folding.SourceCodeFoldingPreferenceBlock; -import org.eclipse.jface.preference.PreferencePage; - -/** - * A preference block for folding of Shell Script commands. - */ -public class ShellCodeFoldingPreferenceBlock extends SourceCodeFoldingPreferenceBlock { - public ShellCodeFoldingPreferenceBlock(OverlayPreferenceStore store, PreferencePage page) { - super(store, page); - } - - @Override - protected String getInitiallyFoldMethodsText() { - return "Functions"; - } - - @Override - protected boolean supportsClassFolding() { - return false; - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/folding/ShellCommentFoldingBlockProvider.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/folding/ShellCommentFoldingBlockProvider.java deleted file mode 100644 index a3cbbaf..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/folding/ShellCommentFoldingBlockProvider.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text.folding; - -import org.eclipse.dltk.sh.ui.Activator; -import org.eclipse.dltk.sh.ui.text.IShellPartitions; -import org.eclipse.dltk.ui.text.folding.IFoldingContent; -import org.eclipse.dltk.ui.text.folding.PartitioningFoldingBlockProvider; - -public class ShellCommentFoldingBlockProvider extends PartitioningFoldingBlockProvider { - - public ShellCommentFoldingBlockProvider() { - super(Activator.getDefault().getTextTools()); - } - - @Override - public void computeFoldableBlocks(IFoldingContent content) { - if (isFoldingComments()) { - computeBlocksForPartitionType(content, IShellPartitions.COMMENT_CONTENT_TYPE, FoldingBlockKind.COMMENT, - isCollapseComments()); - } - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/folding/ShellCommentFoldingPreferenceBlock.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/folding/ShellCommentFoldingPreferenceBlock.java deleted file mode 100644 index e69b5e5..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/text/folding/ShellCommentFoldingPreferenceBlock.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Peter Palaga - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text.folding; - -import org.eclipse.dltk.ui.PreferenceConstants; -import org.eclipse.dltk.ui.preferences.OverlayPreferenceStore; -import org.eclipse.dltk.ui.preferences.PreferencesMessages; -import org.eclipse.dltk.ui.text.folding.DocumentationFoldingPreferenceBlock; -import org.eclipse.jface.preference.PreferencePage; -import org.eclipse.swt.widgets.Group; - -/** - * A preference block for folding of Shell Script comments. - */ -public class ShellCommentFoldingPreferenceBlock extends DocumentationFoldingPreferenceBlock { - - public ShellCommentFoldingPreferenceBlock(OverlayPreferenceStore store, PreferencePage page) { - super(store, page); - } - - /** - * Overridden to add just the "Comments" checkbox rather than both - * "Comments" and "Header comments" as it is done in the super class. It is - * because we do not detect header comments and therefore we cannot fold - * them separately. - * - * @see org.eclipse.dltk.ui.text.folding.DocumentationFoldingPreferenceBlock#addInitiallyFoldOptions(org.eclipse.swt.widgets.Group) - */ - @Override - protected void addInitiallyFoldOptions(Group group) { - createCheckBox(group, PreferencesMessages.FoldingConfigurationBlock_initiallyFoldComments, - PreferenceConstants.EDITOR_FOLDING_INIT_COMMENTS); - } - -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/wizards/NewShellScriptFilePage.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/wizards/NewShellScriptFilePage.java deleted file mode 100644 index fa62e5b..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/wizards/NewShellScriptFilePage.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.eclipse.dltk.sh.ui.wizards; - -import org.eclipse.dltk.sh.core.ShelledNature; -import org.eclipse.dltk.ui.wizards.NewSourceModulePage; - -public class NewShellScriptFilePage extends NewSourceModulePage { - - @Override - protected String getPageTitle() { - return "Shell Script"; - } - - @Override - protected String getPageDescription() { - return "Create a new Shell Script."; - } - - @Override - protected String getRequiredNature() { - return ShelledNature.SHELLED_NATURE; - } -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/wizards/NewShellScriptFileWizard.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/wizards/NewShellScriptFileWizard.java deleted file mode 100644 index b1ea1dd..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/wizards/NewShellScriptFileWizard.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.eclipse.dltk.sh.ui.wizards; - -import org.eclipse.dltk.ui.DLTKUIPlugin; -import org.eclipse.dltk.ui.wizards.NewSourceModulePage; -import org.eclipse.dltk.ui.wizards.NewSourceModuleWizard; - -public class NewShellScriptFileWizard extends NewSourceModuleWizard { - - public NewShellScriptFileWizard() { - setWindowTitle("New Shell Script"); - setDialogSettings(DLTKUIPlugin.getDefault().getDialogSettings()); - } - - @Override - protected NewSourceModulePage createNewSourceModulePage() { - return new NewShellScriptFilePage(); - } -} diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/wizards/ShellScriptProjectWizard.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/wizards/ShellScriptProjectWizard.java deleted file mode 100644 index f91d120..0000000 --- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/ui/wizards/ShellScriptProjectWizard.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.eclipse.dltk.sh.ui.wizards; - -import org.eclipse.dltk.sh.core.ShelledNature; -import org.eclipse.dltk.ui.DLTKUIPlugin; -import org.eclipse.dltk.ui.wizards.ProjectWizard; -import org.eclipse.dltk.ui.wizards.ProjectWizardFirstPage; -import org.eclipse.dltk.ui.wizards.ProjectWizardSecondPage; - -public class ShellScriptProjectWizard extends ProjectWizard { - - public ShellScriptProjectWizard() { - setWindowTitle("New Shell Script Project"); - setDialogSettings(DLTKUIPlugin.getDefault().getDialogSettings()); - } - - @Override - public String getScriptNature() { - return ShelledNature.SHELLED_NATURE; - } - - @Override - public void addPages() { - super.addPages(); - ProjectWizardFirstPage firstPage = new ProjectWizardFirstPage() { - - @Override - protected boolean interpeterRequired() { - return false; - } - }; - - // First page - firstPage.setTitle("Shell Script Project"); - firstPage.setDescription("Create a new Shell Script project."); - addPage(firstPage); - - // Second page - ProjectWizardSecondPage secondPage = new ProjectWizardSecondPage(firstPage); - addPage(secondPage); - } -} diff --git a/tests/org.eclipse.dltk.sh.ui.tests/pom.xml b/tests/org.eclipse.dltk.sh.ui.tests/pom.xml index 052adba..0cd74e3 100644 --- a/tests/org.eclipse.dltk.sh.ui.tests/pom.xml +++ b/tests/org.eclipse.dltk.sh.ui.tests/pom.xml @@ -33,8 +33,8 @@ **/Test*.class ${os-jvm-flags} ${tycho.testArgLine} - org.eclipse.dltk.sh.ui.tests - org.eclipse.dltk.sh.ui.tests.AllTests + org.eclipse.dltk.sh.internal.ui.tests + org.eclipse.dltk.sh.internal.ui.tests.AllTests true true org.eclipse.platform.ide diff --git a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/tests/AllTests.java b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/tests/AllTests.java new file mode 100644 index 0000000..90dc3ae --- /dev/null +++ b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/tests/AllTests.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.tests; + +import org.eclipse.dltk.sh.internal.ui.text.tests.TextSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * All tests wrapper. + * + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ TextSuite.class }) +public class AllTests { +} diff --git a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/AbstractScannerTester.java b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/AbstractScannerTester.java new file mode 100644 index 0000000..a6d4539 --- /dev/null +++ b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/AbstractScannerTester.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2010 Mat Booth and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text.tests; + +import org.eclipse.dltk.internal.ui.text.DLTKColorManager; +import org.eclipse.dltk.ui.text.IColorManager; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.RuleBasedScanner; +import org.junit.Before; + +/** + * Common base class for rules-based scanner tests. + */ +@SuppressWarnings("restriction") +public abstract class AbstractScannerTester { + + protected IColorManager cm = new DLTKColorManager(); + protected RuleBasedScanner scanner; + + /** + * Reset the scanner before every test. + */ + @Before + public void setup() { + scanner = getScanner(); + scanner.setRange(new Document(getText()), 0, getText().length()); + } + + /** + * To be implemented by the test. + * + * @return an instance of the scanner under test + */ + protected abstract RuleBasedScanner getScanner(); + + /** + * To be implemented by the test. + * + * @return the text that will be used to test the scanner + */ + protected abstract String getText(); + + /** + * Gets the nth token from the scanner's document. + * + * @param n + * 1 for the very next token, 2 for the token after that, etc + * @return the nth token + */ + protected IToken getNthToken(int n) { + for (int i = 0; i < n - 1; i++) { + scanner.nextToken(); + } + return scanner.nextToken(); + } + + /** + * Gets the very next token from the scanner's document. + * + * @return the next token + */ + protected IToken getNextToken() { + return getNthToken(1); + } +} diff --git a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/AssignmentRuleTest.java b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/AssignmentRuleTest.java new file mode 100644 index 0000000..2d47e5b --- /dev/null +++ b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/AssignmentRuleTest.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 Mat Booth and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Mat Booth + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text.tests; + +import org.eclipse.dltk.sh.internal.ui.text.AssignmentDetector; +import org.eclipse.dltk.sh.internal.ui.text.AssignmentRule; +import org.eclipse.dltk.sh.internal.ui.text.IShellPartitions; +import org.eclipse.jface.text.rules.Token; +import org.junit.Assert; +import org.junit.Test; + +/** + * Tests the assignment rule that detects variable assignments. + */ +public class AssignmentRuleTest { + + // Mock objects + private MockScanner fScanner; + + // Objects under test + private static AssignmentRule fRule = new AssignmentRule(new AssignmentDetector(), + Token.UNDEFINED, new Token(IShellPartitions.PARAM_CONTENT_TYPE)); + + /** + * Match simple variable assignments. + */ + @Test + public void testAssignmentMatch() { + fScanner = new MockScanner("VAR=assignment"); + Assert.assertFalse(fRule.evaluate(fScanner).isUndefined()); + Assert.assertEquals("VAR", fScanner.getBuffer().substring(0, fScanner.getOffset())); + } + + /** + * Match assignments to shell array variable indexes. + */ + @Test + public void testArrayIndexAssignmentMatch() { + fScanner = new MockScanner("VAR[2]=assignment"); + Assert.assertFalse(fRule.evaluate(fScanner).isUndefined()); + Assert.assertEquals("VAR[2]", fScanner.getBuffer().substring(0, fScanner.getOffset())); + } + + /** + * The equals MUST immediately follow the var-name, otherwise don't match. + */ + @Test + public void testNonAssignmentMatch() { + fScanner = new MockScanner("VAR = assignment"); + Assert.assertTrue(fRule.evaluate(fScanner).isUndefined()); + Assert.assertEquals("", fScanner.getBuffer().substring(0, fScanner.getOffset())); + } +} diff --git a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/DollarBraceCountingRuleTest.java b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/DollarBraceCountingRuleTest.java new file mode 100644 index 0000000..8e99cd8 --- /dev/null +++ b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/DollarBraceCountingRuleTest.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2009 Mat Booth and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text.tests; + +import org.eclipse.dltk.sh.internal.ui.text.DollarBraceCountingRule; +import org.eclipse.dltk.sh.internal.ui.text.IShellPartitions; +import org.eclipse.jface.text.rules.Token; +import org.junit.Assert; +import org.junit.Test; + +/** + * Tests the dollar-prefixed brace-counting single-line rule. Basically we're + * testing to make sure syntax highlighting is correct for ${} and $() blocks. + */ +public class DollarBraceCountingRuleTest { + + // Mock objects + private MockScanner fScanner; + + // Objects under test + private static DollarBraceCountingRule fRule = new DollarBraceCountingRule( + '{', '}', new Token(IShellPartitions.PARAM_CONTENT_TYPE), '\\'); + + /** + * Highlight a simple pair of dollar-prefixed braces. + */ + @Test + public void testSimpleMatch() { + fScanner = new MockScanner("${basic}test}"); + Assert.assertFalse(fRule.evaluate(fScanner).isUndefined()); + Assert.assertEquals("${basic}", fScanner.getBuffer().substring(0, + fScanner.getOffset())); + } + + /** + * Highlight a pair of braces enclosing escaped braces. + */ + @Test + public void testEscapedBraceMatch() { + fScanner = new MockScanner("${basic\\}\\}}test}"); + Assert.assertFalse(fRule.evaluate(fScanner).isUndefined()); + Assert.assertEquals("${basic\\}\\}}", fScanner.getBuffer().substring(0, + fScanner.getOffset())); + } + + /** + * Highlight the correct amount of nested braces. + */ + @Test + public void testNestedBraceMatch() { + fScanner = new MockScanner("${a{b{cd}e}f}g}"); + Assert.assertFalse(fRule.evaluate(fScanner).isUndefined()); + Assert.assertEquals("${a{b{cd}e}f}", fScanner.getBuffer().substring(0, + fScanner.getOffset())); + } + + /** + * Highlight everything up to the end of the line, if that occurs before the + * final closing brace. + */ + @Test + public void testEndOfLineMatch() { + fScanner = new MockScanner("${a{b}c\nd}"); + Assert.assertFalse(fRule.evaluate(fScanner).isUndefined()); + Assert.assertEquals("${a{b}c\n", fScanner.getBuffer().substring(0, + fScanner.getOffset())); + } + + /** + * Do not highlight if EOF interrupts the pattern. + */ + @Test + public void testEndOfFileMatch() { + fScanner = new MockScanner("${end of file is here:"); + Assert.assertTrue(fRule.evaluate(fScanner).isUndefined()); + Assert.assertEquals("", fScanner.getBuffer().substring(0, + fScanner.getOffset())); + } +} diff --git a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/DollarRuleTest.java b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/DollarRuleTest.java new file mode 100644 index 0000000..a1a3e49 --- /dev/null +++ b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/DollarRuleTest.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text.tests; + +import org.eclipse.dltk.sh.internal.ui.text.DollarDetector; +import org.eclipse.dltk.sh.internal.ui.text.DollarRule; +import org.eclipse.dltk.sh.internal.ui.text.IShellPartitions; +import org.eclipse.jface.text.rules.Token; +import org.junit.Assert; +import org.junit.Test; + +/** + * Tests the dollar rule that detects $var style parameter expansions. + */ +public class DollarRuleTest { + + // Mock objects + private MockScanner fScanner; + + // Objects under test + private static DollarRule fRule = new DollarRule(new DollarDetector(), Token.UNDEFINED, + new Token(IShellPartitions.PARAM_CONTENT_TYPE)); + + /** + * Don't match ${} syntax because that is taken care of in another rule. + */ + @Test + public void testDollarBraceMatch() { + fScanner = new MockScanner("${braces}"); + Assert.assertTrue(fRule.evaluate(fScanner).isUndefined()); + Assert.assertEquals("", fScanner.getBuffer().substring(0, fScanner.getOffset())); + } + + /** + * Match simple alpha-numeric vars that may contain underscores. Don't match + * [ or ] because array index references must be inside braces. + */ + @Test + public void testDollarMatch() { + fScanner = new MockScanner("$alpha_01[5] numeric vars"); + Assert.assertFalse(fRule.evaluate(fScanner).isUndefined()); + Assert.assertEquals("$alpha_01", fScanner.getBuffer().substring(0, fScanner.getOffset())); + } + + /** + * If the variable starts with a digit, then it's a reference to a + * positional parameter and only that one digit may be highlighted + * (characters after the digit are ignored and parameters 10+ must be + * referenced using the brace syntax.) Special parameters are detected + * similarly. + */ + @Test + public void testPositionalSpecialMatch() { + // List of valid special or positional parameters + char specials[] = new char[] { '*', '@', '#', '?', '-', '$', '!', '_', '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', }; + for (int i = '!'; i <= '~'; i++) { + String s = "$" + Character.toString((char) i); + fScanner = new MockScanner(s + "some more text"); + + // Make sure that special/positional parameters are matched + // correctly + boolean isSpecial = false; + for (int j = 0; j < specials.length; j++) { + if ((char) i == specials[j]) { + Assert.assertFalse("Testing Special " + s, fRule.evaluate(fScanner).isUndefined()); + Assert.assertEquals(s, fScanner.getBuffer().substring(0, fScanner.getOffset())); + isSpecial = true; + break; + } + } + + if (!isSpecial) { + if (Character.isLetter((char) i)) { + // Make sure that valid characters that are not specials are + // matched normally + Assert.assertFalse("Testing Not Special " + s, fRule.evaluate(fScanner).isUndefined()); + Assert.assertEquals(s + "some", fScanner.getBuffer().substring(0, fScanner.getOffset())); + } else { + // Make sure that invalid characters are not matched at all + Assert.assertTrue("Testing Not Special " + s, fRule.evaluate(fScanner).isUndefined()); + Assert.assertEquals("", fScanner.getBuffer().substring(0, fScanner.getOffset())); + } + } + } + } +} diff --git a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/DoubleQuoteScannerTest.java b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/DoubleQuoteScannerTest.java new file mode 100644 index 0000000..cdfd9c0 --- /dev/null +++ b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/DoubleQuoteScannerTest.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2010 Mat Booth and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text.tests; + +import static org.junit.Assert.assertEquals; + +import org.eclipse.dltk.sh.internal.ui.Activator; +import org.eclipse.dltk.sh.internal.ui.IShellColorConstants; +import org.eclipse.dltk.sh.internal.ui.text.DoubleQuoteScanner; +import org.eclipse.jface.text.TextAttribute; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.RuleBasedScanner; +import org.junit.Test; + +/** + * Test the scanner for double quote partitions. + */ +public class DoubleQuoteScannerTest extends AbstractScannerTester { + + @Override + protected RuleBasedScanner getScanner() { + return new DoubleQuoteScanner(cm, Activator.getDefault().getPreferenceStore()); + } + + @Override + protected String getText() { + return "x${var}x$var`eval`x$(eval)"; + } + + /** + * Tests that we correctly highlight $dollar style parameter expansions + * within interpolated strings. + */ + @Test + public void testDollar() { + IToken token = getNthToken(4); + assertEquals(4, scanner.getTokenLength()); + assertEquals(8, scanner.getTokenOffset()); + TextAttribute ta = (TextAttribute) token.getData(); + assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_VARIABLE)); + } + + /** + * Tests that we correctly highlight ${dollar-brace} style parameter + * expansions within interpolated strings. + */ + @Test + public void testDollarBrace() { + IToken token = getNthToken(2); + assertEquals(6, scanner.getTokenLength()); + assertEquals(1, scanner.getTokenOffset()); + TextAttribute ta = (TextAttribute) token.getData(); + assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_VARIABLE)); + } + + /** + * Tests that we correctly highlight `back-tick` style command substitutions + * within interpolated strings. + */ + @Test + public void testEval() { + IToken token = getNthToken(5); + assertEquals(6, scanner.getTokenLength()); + assertEquals(12, scanner.getTokenOffset()); + TextAttribute ta = (TextAttribute) token.getData(); + assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_EVAL)); + } + + /** + * Tests that we correctly highlight $(dollar-brace) style command + * substitutions within interpolated strings. + */ + @Test + public void testDollarEval() { + IToken token = getNthToken(7); + assertEquals(7, scanner.getTokenLength()); + assertEquals(19, scanner.getTokenOffset()); + TextAttribute ta = (TextAttribute) token.getData(); + assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_EVAL)); + } + + /** + * Everything else should have the default highlighting for this partition + * type. + */ + @Test + public void testDefault() { + IToken token = getNthToken(1); + assertEquals(1, scanner.getTokenLength()); + assertEquals(0, scanner.getTokenOffset()); + TextAttribute ta = (TextAttribute) token.getData(); + assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_DOUBLE_QUOTE)); + + token = getNthToken(2); + assertEquals(1, scanner.getTokenLength()); + assertEquals(7, scanner.getTokenOffset()); + ta = (TextAttribute) token.getData(); + assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_DOUBLE_QUOTE)); + + token = getNthToken(3); + assertEquals(1, scanner.getTokenLength()); + assertEquals(18, scanner.getTokenOffset()); + ta = (TextAttribute) token.getData(); + assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_DOUBLE_QUOTE)); + } +} diff --git a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/EvalScannerTest.java b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/EvalScannerTest.java new file mode 100644 index 0000000..e78efda --- /dev/null +++ b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/EvalScannerTest.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2010 Mat Booth and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text.tests; + +import static org.junit.Assert.assertEquals; + +import org.eclipse.dltk.sh.internal.ui.Activator; +import org.eclipse.dltk.sh.internal.ui.IShellColorConstants; +import org.eclipse.dltk.sh.internal.ui.text.EvalScanner; +import org.eclipse.jface.text.TextAttribute; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.RuleBasedScanner; +import org.junit.Test; + +/** + * Test the scanner for command substitution partitions. + */ +public class EvalScannerTest extends AbstractScannerTester { + + @Override + protected RuleBasedScanner getScanner() { + return new EvalScanner(cm, Activator.getDefault().getPreferenceStore()); + } + + @Override + protected String getText() { + return "$vars in command ${substitutions}"; + } + + /** + * Tests that we correctly highlight $dollar style parameter expansions + * within command substitutions. + */ + @Test + public void testDollar() { + IToken token = getNextToken(); + assertEquals(5, scanner.getTokenLength()); + assertEquals(0, scanner.getTokenOffset()); + TextAttribute ta = (TextAttribute) token.getData(); + assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_VARIABLE)); + } + + /** + * Tests that we correctly highlight ${dollar-brace} style parameter + * expansions within command substitutions. + */ + @Test + public void testDollarBrace() { + IToken token = getNthToken(14); + assertEquals(16, scanner.getTokenLength()); + assertEquals(17, scanner.getTokenOffset()); + TextAttribute ta = (TextAttribute) token.getData(); + assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_VARIABLE)); + } + + /** + * Everything else should have the default highlighting for this partition + * type. + */ + @Test + public void testDefault() { + IToken token = getNthToken(3); + assertEquals(1, scanner.getTokenLength()); + assertEquals(6, scanner.getTokenOffset()); + TextAttribute ta = (TextAttribute) token.getData(); + assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_EVAL)); + } +} diff --git a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/MockScanner.java b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/MockScanner.java new file mode 100644 index 0000000..592d4f3 --- /dev/null +++ b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/MockScanner.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2009 Mat Booth and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text.tests; + +import org.eclipse.jface.text.rules.ICharacterScanner; + +/** + * Simple concrete character scanner that we can use to test IPredicateRule and + * IRule implementations. As far as the rule being tested is concerned, this + * scanner is feeding it chunks of a real document. + */ +public class MockScanner implements ICharacterScanner { + + private int fOffset = 0; + private String fBuffer; + + /** + * Dummy scanner on given buffer. + * + * @param buffer + * The buffer. + */ + public MockScanner(String buffer) { + fBuffer = buffer; + } + + /** + * @return The offset. + */ + public int getOffset() { + return fOffset; + } + + /** + * @return The buffer. + */ + public String getBuffer() { + return fBuffer; + } + + @Override + public int getColumn() { + return 0; + } + + @Override + public char[][] getLegalLineDelimiters() { + return new char[][] { { '\r' }, { '\n' }, { '\r', '\n' }, }; + } + + @Override + public int read() { + + if (fOffset < fBuffer.length()) { + return fBuffer.charAt(fOffset++); + } + return EOF; + } + + @Override + public void unread() { + --fOffset; + } +} diff --git a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/TextSuite.java b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/TextSuite.java new file mode 100644 index 0000000..cab03c1 --- /dev/null +++ b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/internal/ui/text/tests/TextSuite.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2009-2011 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexander Kurtakov - initial API and implementation + *******************************************************************************/ +package org.eclipse.dltk.sh.internal.ui.text.tests; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * Test suite for all org.eclipse.dltk.sh.ui.text tests. + * + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ AssignmentRuleTest.class, DollarBraceCountingRuleTest.class, DollarRuleTest.class, + DoubleQuoteScannerTest.class, EvalScannerTest.class }) +public class TextSuite { +} diff --git a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/tests/AllTests.java b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/tests/AllTests.java deleted file mode 100644 index e05d387..0000000 --- a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/tests/AllTests.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.tests; - -import org.eclipse.dltk.sh.ui.text.tests.TextSuite; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -/** - * All tests wrapper. - * - */ -@RunWith(Suite.class) -@Suite.SuiteClasses({ TextSuite.class }) -public class AllTests { -} diff --git a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/AbstractScannerTester.java b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/AbstractScannerTester.java deleted file mode 100644 index 14a2818..0000000 --- a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/AbstractScannerTester.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Mat Booth and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text.tests; - -import org.eclipse.dltk.internal.ui.text.DLTKColorManager; -import org.eclipse.dltk.ui.text.IColorManager; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.RuleBasedScanner; -import org.junit.Before; - -/** - * Common base class for rules-based scanner tests. - */ -@SuppressWarnings("restriction") -public abstract class AbstractScannerTester { - - protected IColorManager cm = new DLTKColorManager(); - protected RuleBasedScanner scanner; - - /** - * Reset the scanner before every test. - */ - @Before - public void setup() { - scanner = getScanner(); - scanner.setRange(new Document(getText()), 0, getText().length()); - } - - /** - * To be implemented by the test. - * - * @return an instance of the scanner under test - */ - protected abstract RuleBasedScanner getScanner(); - - /** - * To be implemented by the test. - * - * @return the text that will be used to test the scanner - */ - protected abstract String getText(); - - /** - * Gets the nth token from the scanner's document. - * - * @param n - * 1 for the very next token, 2 for the token after that, etc - * @return the nth token - */ - protected IToken getNthToken(int n) { - for (int i = 0; i < n - 1; i++) { - scanner.nextToken(); - } - return scanner.nextToken(); - } - - /** - * Gets the very next token from the scanner's document. - * - * @return the next token - */ - protected IToken getNextToken() { - return getNthToken(1); - } -} diff --git a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/AssignmentRuleTest.java b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/AssignmentRuleTest.java deleted file mode 100644 index 8d2dff1..0000000 --- a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/AssignmentRuleTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Mat Booth and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Mat Booth - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text.tests; - -import org.eclipse.dltk.sh.ui.text.AssignmentDetector; -import org.eclipse.dltk.sh.ui.text.AssignmentRule; -import org.eclipse.dltk.sh.ui.text.IShellPartitions; -import org.eclipse.jface.text.rules.Token; -import org.junit.Assert; -import org.junit.Test; - -/** - * Tests the assignment rule that detects variable assignments. - */ -public class AssignmentRuleTest { - - // Mock objects - private MockScanner fScanner; - - // Objects under test - private static AssignmentRule fRule = new AssignmentRule(new AssignmentDetector(), - Token.UNDEFINED, new Token(IShellPartitions.PARAM_CONTENT_TYPE)); - - /** - * Match simple variable assignments. - */ - @Test - public void testAssignmentMatch() { - fScanner = new MockScanner("VAR=assignment"); - Assert.assertFalse(fRule.evaluate(fScanner).isUndefined()); - Assert.assertEquals("VAR", fScanner.getBuffer().substring(0, fScanner.getOffset())); - } - - /** - * Match assignments to shell array variable indexes. - */ - @Test - public void testArrayIndexAssignmentMatch() { - fScanner = new MockScanner("VAR[2]=assignment"); - Assert.assertFalse(fRule.evaluate(fScanner).isUndefined()); - Assert.assertEquals("VAR[2]", fScanner.getBuffer().substring(0, fScanner.getOffset())); - } - - /** - * The equals MUST immediately follow the var-name, otherwise don't match. - */ - @Test - public void testNonAssignmentMatch() { - fScanner = new MockScanner("VAR = assignment"); - Assert.assertTrue(fRule.evaluate(fScanner).isUndefined()); - Assert.assertEquals("", fScanner.getBuffer().substring(0, fScanner.getOffset())); - } -} diff --git a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/DollarBraceCountingRuleTest.java b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/DollarBraceCountingRuleTest.java deleted file mode 100644 index e6d73f3..0000000 --- a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/DollarBraceCountingRuleTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Mat Booth and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text.tests; - -import org.eclipse.dltk.sh.ui.text.DollarBraceCountingRule; -import org.eclipse.dltk.sh.ui.text.IShellPartitions; -import org.eclipse.jface.text.rules.Token; -import org.junit.Assert; -import org.junit.Test; - -/** - * Tests the dollar-prefixed brace-counting single-line rule. Basically we're - * testing to make sure syntax highlighting is correct for ${} and $() blocks. - */ -public class DollarBraceCountingRuleTest { - - // Mock objects - private MockScanner fScanner; - - // Objects under test - private static DollarBraceCountingRule fRule = new DollarBraceCountingRule( - '{', '}', new Token(IShellPartitions.PARAM_CONTENT_TYPE), '\\'); - - /** - * Highlight a simple pair of dollar-prefixed braces. - */ - @Test - public void testSimpleMatch() { - fScanner = new MockScanner("${basic}test}"); - Assert.assertFalse(fRule.evaluate(fScanner).isUndefined()); - Assert.assertEquals("${basic}", fScanner.getBuffer().substring(0, - fScanner.getOffset())); - } - - /** - * Highlight a pair of braces enclosing escaped braces. - */ - @Test - public void testEscapedBraceMatch() { - fScanner = new MockScanner("${basic\\}\\}}test}"); - Assert.assertFalse(fRule.evaluate(fScanner).isUndefined()); - Assert.assertEquals("${basic\\}\\}}", fScanner.getBuffer().substring(0, - fScanner.getOffset())); - } - - /** - * Highlight the correct amount of nested braces. - */ - @Test - public void testNestedBraceMatch() { - fScanner = new MockScanner("${a{b{cd}e}f}g}"); - Assert.assertFalse(fRule.evaluate(fScanner).isUndefined()); - Assert.assertEquals("${a{b{cd}e}f}", fScanner.getBuffer().substring(0, - fScanner.getOffset())); - } - - /** - * Highlight everything up to the end of the line, if that occurs before the - * final closing brace. - */ - @Test - public void testEndOfLineMatch() { - fScanner = new MockScanner("${a{b}c\nd}"); - Assert.assertFalse(fRule.evaluate(fScanner).isUndefined()); - Assert.assertEquals("${a{b}c\n", fScanner.getBuffer().substring(0, - fScanner.getOffset())); - } - - /** - * Do not highlight if EOF interrupts the pattern. - */ - @Test - public void testEndOfFileMatch() { - fScanner = new MockScanner("${end of file is here:"); - Assert.assertTrue(fRule.evaluate(fScanner).isUndefined()); - Assert.assertEquals("", fScanner.getBuffer().substring(0, - fScanner.getOffset())); - } -} diff --git a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/DollarRuleTest.java b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/DollarRuleTest.java deleted file mode 100644 index bab52c4..0000000 --- a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/DollarRuleTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text.tests; - -import org.eclipse.dltk.sh.ui.text.DollarDetector; -import org.eclipse.dltk.sh.ui.text.DollarRule; -import org.eclipse.dltk.sh.ui.text.IShellPartitions; -import org.eclipse.jface.text.rules.Token; -import org.junit.Assert; -import org.junit.Test; - -/** - * Tests the dollar rule that detects $var style parameter expansions. - */ -public class DollarRuleTest { - - // Mock objects - private MockScanner fScanner; - - // Objects under test - private static DollarRule fRule = new DollarRule(new DollarDetector(), Token.UNDEFINED, - new Token(IShellPartitions.PARAM_CONTENT_TYPE)); - - /** - * Don't match ${} syntax because that is taken care of in another rule. - */ - @Test - public void testDollarBraceMatch() { - fScanner = new MockScanner("${braces}"); - Assert.assertTrue(fRule.evaluate(fScanner).isUndefined()); - Assert.assertEquals("", fScanner.getBuffer().substring(0, fScanner.getOffset())); - } - - /** - * Match simple alpha-numeric vars that may contain underscores. Don't match - * [ or ] because array index references must be inside braces. - */ - @Test - public void testDollarMatch() { - fScanner = new MockScanner("$alpha_01[5] numeric vars"); - Assert.assertFalse(fRule.evaluate(fScanner).isUndefined()); - Assert.assertEquals("$alpha_01", fScanner.getBuffer().substring(0, fScanner.getOffset())); - } - - /** - * If the variable starts with a digit, then it's a reference to a - * positional parameter and only that one digit may be highlighted - * (characters after the digit are ignored and parameters 10+ must be - * referenced using the brace syntax.) Special parameters are detected - * similarly. - */ - @Test - public void testPositionalSpecialMatch() { - // List of valid special or positional parameters - char specials[] = new char[] { '*', '@', '#', '?', '-', '$', '!', '_', '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', }; - for (int i = '!'; i <= '~'; i++) { - String s = "$" + Character.toString((char) i); - fScanner = new MockScanner(s + "some more text"); - - // Make sure that special/positional parameters are matched - // correctly - boolean isSpecial = false; - for (int j = 0; j < specials.length; j++) { - if ((char) i == specials[j]) { - Assert.assertFalse("Testing Special " + s, fRule.evaluate(fScanner).isUndefined()); - Assert.assertEquals(s, fScanner.getBuffer().substring(0, fScanner.getOffset())); - isSpecial = true; - break; - } - } - - if (!isSpecial) { - if (Character.isLetter((char) i)) { - // Make sure that valid characters that are not specials are - // matched normally - Assert.assertFalse("Testing Not Special " + s, fRule.evaluate(fScanner).isUndefined()); - Assert.assertEquals(s + "some", fScanner.getBuffer().substring(0, fScanner.getOffset())); - } else { - // Make sure that invalid characters are not matched at all - Assert.assertTrue("Testing Not Special " + s, fRule.evaluate(fScanner).isUndefined()); - Assert.assertEquals("", fScanner.getBuffer().substring(0, fScanner.getOffset())); - } - } - } - } -} diff --git a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/DoubleQuoteScannerTest.java b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/DoubleQuoteScannerTest.java deleted file mode 100644 index 3ab6f03..0000000 --- a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/DoubleQuoteScannerTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Mat Booth and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text.tests; - -import static org.junit.Assert.assertEquals; - -import org.eclipse.dltk.sh.ui.Activator; -import org.eclipse.dltk.sh.ui.IShellColorConstants; -import org.eclipse.dltk.sh.ui.text.DoubleQuoteScanner; -import org.eclipse.jface.text.TextAttribute; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.RuleBasedScanner; -import org.junit.Test; - -/** - * Test the scanner for double quote partitions. - */ -public class DoubleQuoteScannerTest extends AbstractScannerTester { - - @Override - protected RuleBasedScanner getScanner() { - return new DoubleQuoteScanner(cm, Activator.getDefault().getPreferenceStore()); - } - - @Override - protected String getText() { - return "x${var}x$var`eval`x$(eval)"; - } - - /** - * Tests that we correctly highlight $dollar style parameter expansions - * within interpolated strings. - */ - @Test - public void testDollar() { - IToken token = getNthToken(4); - assertEquals(4, scanner.getTokenLength()); - assertEquals(8, scanner.getTokenOffset()); - TextAttribute ta = (TextAttribute) token.getData(); - assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_VARIABLE)); - } - - /** - * Tests that we correctly highlight ${dollar-brace} style parameter - * expansions within interpolated strings. - */ - @Test - public void testDollarBrace() { - IToken token = getNthToken(2); - assertEquals(6, scanner.getTokenLength()); - assertEquals(1, scanner.getTokenOffset()); - TextAttribute ta = (TextAttribute) token.getData(); - assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_VARIABLE)); - } - - /** - * Tests that we correctly highlight `back-tick` style command substitutions - * within interpolated strings. - */ - @Test - public void testEval() { - IToken token = getNthToken(5); - assertEquals(6, scanner.getTokenLength()); - assertEquals(12, scanner.getTokenOffset()); - TextAttribute ta = (TextAttribute) token.getData(); - assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_EVAL)); - } - - /** - * Tests that we correctly highlight $(dollar-brace) style command - * substitutions within interpolated strings. - */ - @Test - public void testDollarEval() { - IToken token = getNthToken(7); - assertEquals(7, scanner.getTokenLength()); - assertEquals(19, scanner.getTokenOffset()); - TextAttribute ta = (TextAttribute) token.getData(); - assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_EVAL)); - } - - /** - * Everything else should have the default highlighting for this partition - * type. - */ - @Test - public void testDefault() { - IToken token = getNthToken(1); - assertEquals(1, scanner.getTokenLength()); - assertEquals(0, scanner.getTokenOffset()); - TextAttribute ta = (TextAttribute) token.getData(); - assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_DOUBLE_QUOTE)); - - token = getNthToken(2); - assertEquals(1, scanner.getTokenLength()); - assertEquals(7, scanner.getTokenOffset()); - ta = (TextAttribute) token.getData(); - assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_DOUBLE_QUOTE)); - - token = getNthToken(3); - assertEquals(1, scanner.getTokenLength()); - assertEquals(18, scanner.getTokenOffset()); - ta = (TextAttribute) token.getData(); - assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_DOUBLE_QUOTE)); - } -} diff --git a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/EvalScannerTest.java b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/EvalScannerTest.java deleted file mode 100644 index f7ba2e4..0000000 --- a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/EvalScannerTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Mat Booth and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text.tests; - -import static org.junit.Assert.assertEquals; - -import org.eclipse.dltk.sh.ui.Activator; -import org.eclipse.dltk.sh.ui.IShellColorConstants; -import org.eclipse.dltk.sh.ui.text.EvalScanner; -import org.eclipse.jface.text.TextAttribute; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.RuleBasedScanner; -import org.junit.Test; - -/** - * Test the scanner for command substitution partitions. - */ -public class EvalScannerTest extends AbstractScannerTester { - - @Override - protected RuleBasedScanner getScanner() { - return new EvalScanner(cm, Activator.getDefault().getPreferenceStore()); - } - - @Override - protected String getText() { - return "$vars in command ${substitutions}"; - } - - /** - * Tests that we correctly highlight $dollar style parameter expansions - * within command substitutions. - */ - @Test - public void testDollar() { - IToken token = getNextToken(); - assertEquals(5, scanner.getTokenLength()); - assertEquals(0, scanner.getTokenOffset()); - TextAttribute ta = (TextAttribute) token.getData(); - assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_VARIABLE)); - } - - /** - * Tests that we correctly highlight ${dollar-brace} style parameter - * expansions within command substitutions. - */ - @Test - public void testDollarBrace() { - IToken token = getNthToken(14); - assertEquals(16, scanner.getTokenLength()); - assertEquals(17, scanner.getTokenOffset()); - TextAttribute ta = (TextAttribute) token.getData(); - assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_VARIABLE)); - } - - /** - * Everything else should have the default highlighting for this partition - * type. - */ - @Test - public void testDefault() { - IToken token = getNthToken(3); - assertEquals(1, scanner.getTokenLength()); - assertEquals(6, scanner.getTokenOffset()); - TextAttribute ta = (TextAttribute) token.getData(); - assertEquals(ta.getForeground(), cm.getColor(IShellColorConstants.SHELL_EVAL)); - } -} diff --git a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/MockScanner.java b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/MockScanner.java deleted file mode 100644 index e9d0d03..0000000 --- a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/MockScanner.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Mat Booth and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text.tests; - -import org.eclipse.jface.text.rules.ICharacterScanner; - -/** - * Simple concrete character scanner that we can use to test IPredicateRule and - * IRule implementations. As far as the rule being tested is concerned, this - * scanner is feeding it chunks of a real document. - */ -public class MockScanner implements ICharacterScanner { - - private int fOffset = 0; - private String fBuffer; - - /** - * Dummy scanner on given buffer. - * - * @param buffer - * The buffer. - */ - public MockScanner(String buffer) { - fBuffer = buffer; - } - - /** - * @return The offset. - */ - public int getOffset() { - return fOffset; - } - - /** - * @return The buffer. - */ - public String getBuffer() { - return fBuffer; - } - - @Override - public int getColumn() { - return 0; - } - - @Override - public char[][] getLegalLineDelimiters() { - return new char[][] { { '\r' }, { '\n' }, { '\r', '\n' }, }; - } - - @Override - public int read() { - - if (fOffset < fBuffer.length()) { - return fBuffer.charAt(fOffset++); - } - return EOF; - } - - @Override - public void unread() { - --fOffset; - } -} diff --git a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/TextSuite.java b/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/TextSuite.java deleted file mode 100644 index 8a80805..0000000 --- a/tests/org.eclipse.dltk.sh.ui.tests/src/org/eclipse/dltk/sh/ui/text/tests/TextSuite.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009-2011 Red Hat Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexander Kurtakov - initial API and implementation - *******************************************************************************/ -package org.eclipse.dltk.sh.ui.text.tests; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -/** - * Test suite for all org.eclipse.dltk.sh.ui.text tests. - * - */ -@RunWith(Suite.class) -@Suite.SuiteClasses({ AssignmentRuleTest.class, DollarBraceCountingRuleTest.class, DollarRuleTest.class, - DoubleQuoteScannerTest.class, EvalScannerTest.class }) -public class TextSuite { -} -- cgit v1.2.3