File tree Expand file tree Collapse file tree 2 files changed +15
-9
lines changed
org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal Expand file tree Collapse file tree 2 files changed +15
-9
lines changed Original file line number Diff line number Diff line change 1111 *******************************************************************************/
1212package org .eclipse .tm4e .ui .internal .preferences ;
1313
14- import java .util .Arrays ;
15-
1614import org .eclipse .jdt .annotation .Nullable ;
1715import org .eclipse .jface .text .Document ;
1816import org .eclipse .jface .text .IDocument ;
2826import org .eclipse .swt .widgets .Shell ;
2927import org .eclipse .text .templates .TemplatePersistenceData ;
3028import org .eclipse .tm4e .core .grammar .IGrammar ;
31- import org .eclipse .tm4e .registry .IGrammarDefinition ;
3229import org .eclipse .tm4e .registry .ITMScope ;
3330import org .eclipse .tm4e .registry .TMEclipseRegistryPlugin ;
3431import org .eclipse .tm4e .ui .TMUIPlugin ;
@@ -108,12 +105,7 @@ private void selectedCodeTemplateChanged() {
108105 if (selectedTemplate != null ) {
109106
110107 final String id = selectedTemplate .getContextTypeId ();
111-
112- final IGrammarDefinition [] grammarDefinitions = TMEclipseRegistryPlugin .getGrammarRegistryManager ().getDefinitions ();
113- final ITMScope scope = Arrays .stream (grammarDefinitions )
114- .map (IGrammarDefinition ::getScope )
115- .filter (s -> id .equals (CodeTemplateContextTypeUtils .toContextTypeId (s )))
116- .findFirst ().orElse (null );
108+ final ITMScope scope = CodeTemplateContextTypeUtils .findScopeFor (id );
117109
118110 if (scope != null ) {
119111 final IGrammar languageGrammar = TMEclipseRegistryPlugin .getGrammarRegistryManager ().getGrammarForScope (scope );
Original file line number Diff line number Diff line change 1111 *******************************************************************************/
1212package org .eclipse .tm4e .ui .internal .utils ;
1313
14+ import java .util .Arrays ;
15+
16+ import org .eclipse .jdt .annotation .Nullable ;
17+ import org .eclipse .tm4e .registry .IGrammarDefinition ;
1418import org .eclipse .tm4e .registry .ITMScope ;
19+ import org .eclipse .tm4e .registry .TMEclipseRegistryPlugin ;
1520import org .eclipse .tm4e .ui .TMUIPlugin ;
1621
1722public class CodeTemplateContextTypeUtils {
@@ -28,4 +33,13 @@ public static String toContextTypeId(final ITMScope languageScope) {
2833 return CONTEXT_TYPE_ID_PREFIX + contextTypeIdSuffix ;
2934 }
3035
36+ public static @ Nullable ITMScope findScopeFor (final String contextTypeId ) {
37+ final IGrammarDefinition [] grammarDefinitions = TMEclipseRegistryPlugin .getGrammarRegistryManager ().getDefinitions ();
38+
39+ return Arrays .stream (grammarDefinitions )
40+ .map (IGrammarDefinition ::getScope )
41+ .filter (scope -> contextTypeId .equals (CodeTemplateContextTypeUtils .toContextTypeId (scope )))
42+ .findFirst ().orElse (null );
43+ }
44+
3145}
You can’t perform that action at this time.
0 commit comments