@@ -97,39 +97,6 @@ public abstract class SemanticHighlighterBase extends JavaParserResultTask {
97
97
public static final String JAVA_INLINE_HINT_CHAINED_TYPES = "javaInlineHintChainedTypes" ; //NOI18N
98
98
public static final String JAVA_INLINE_HINT_VAR_TYPE = "javaInlineHintVarType" ; //NOI18N
99
99
100
- private static final Map <String , Boolean > DEFAULT_VALUES ;
101
-
102
- static {
103
- Map <String , Boolean > defaultValuesBuilder = new HashMap <>();
104
- defaultValuesBuilder .put (JAVA_INLINE_HINT_PARAMETER_NAME , true );
105
- defaultValuesBuilder .put (JAVA_INLINE_HINT_CHAINED_TYPES , false );
106
- defaultValuesBuilder .put (JAVA_INLINE_HINT_VAR_TYPE , false );
107
- DEFAULT_VALUES = Collections .unmodifiableMap (defaultValuesBuilder );
108
- }
109
-
110
- private static boolean javaInlineHintParameterName ;
111
- private static boolean javaInlineHintChainedTypes ;
112
- private static boolean javaInlineHintVarType ;
113
-
114
- private static boolean isJavaInlineHintParameterName () {
115
- return javaInlineHintParameterName ;
116
- }
117
-
118
- private static boolean isJavaInlineHintChainedTypes () {
119
- return javaInlineHintChainedTypes ;
120
- }
121
-
122
- private static boolean isJavaInlineHintVarType () {
123
- return javaInlineHintVarType ;
124
- }
125
-
126
- private static void updateFromPreferences () {
127
- Preferences preferences = NbPreferences .root ().node ("/org/netbeans/modules/java/editor/InlineHints/default" );
128
- javaInlineHintParameterName = preferences .getBoolean (JAVA_INLINE_HINT_PARAMETER_NAME , DEFAULT_VALUES .get (JAVA_INLINE_HINT_PARAMETER_NAME ));
129
- javaInlineHintChainedTypes = preferences .getBoolean (JAVA_INLINE_HINT_CHAINED_TYPES , DEFAULT_VALUES .get (JAVA_INLINE_HINT_CHAINED_TYPES ));
130
- javaInlineHintVarType = preferences .getBoolean (JAVA_INLINE_HINT_VAR_TYPE , DEFAULT_VALUES .get (JAVA_INLINE_HINT_VAR_TYPE ));
131
- }
132
-
133
100
private AtomicBoolean cancel = new AtomicBoolean ();
134
101
135
102
protected SemanticHighlighterBase () {
@@ -189,9 +156,11 @@ public Class<? extends Scheduler> getSchedulerClass() {
189
156
protected abstract boolean process (CompilationInfo info , final Document doc );
190
157
191
158
protected boolean process (CompilationInfo info , final Document doc , ErrorDescriptionSetter setter ) {
192
- updateFromPreferences ();
159
+ return process (info , doc , Settings .getDefault (), setter );
160
+ }
193
161
194
- DetectorVisitor v = new DetectorVisitor (info , doc , cancel );
162
+ protected boolean process (CompilationInfo info , final Document doc , Settings settings , ErrorDescriptionSetter setter ) {
163
+ DetectorVisitor v = new DetectorVisitor (info , doc , settings , cancel );
195
164
196
165
Map <Token , Coloring > newColoring = new IdentityHashMap <>();
197
166
@@ -315,8 +284,9 @@ public String toString() {
315
284
316
285
private static class DetectorVisitor extends CancellableTreePathScanner <Void , Void > {
317
286
318
- private org .netbeans .api .java .source .CompilationInfo info ;
319
- private Document doc ;
287
+ private final org .netbeans .api .java .source .CompilationInfo info ;
288
+ private final Document doc ;
289
+ private final Settings settings ;
320
290
private Map <Element , List <Use >> type2Uses ;
321
291
private Map <Tree , List <Token >> tree2Tokens ;
322
292
private List <Token > contextKeywords ;
@@ -327,11 +297,12 @@ private static class DetectorVisitor extends CancellableTreePathScanner<Void, Vo
327
297
private SourcePositions sourcePositions ;
328
298
private ExecutableElement recursionDetector ;
329
299
330
- private DetectorVisitor (org .netbeans .api .java .source .CompilationInfo info , final Document doc , AtomicBoolean cancel ) {
300
+ private DetectorVisitor (org .netbeans .api .java .source .CompilationInfo info , final Document doc , Settings settings , AtomicBoolean cancel ) {
331
301
super (cancel );
332
302
333
303
this .info = info ;
334
304
this .doc = doc ;
305
+ this .settings = settings ;
335
306
type2Uses = new HashMap <Element , List <Use >>();
336
307
tree2Tokens = new IdentityHashMap <Tree , List <Token >>();
337
308
contextKeywords = new ArrayList <>();
@@ -787,7 +758,7 @@ public Void visitMethodInvocation(MethodInvocationTree tree, Void p) {
787
758
}
788
759
789
760
private void addChainedTypes (TreePath current ) {
790
- if (! isJavaInlineHintChainedTypes () ) {
761
+ if (! settings . javaInlineHintChainedTypes ) {
791
762
return ;
792
763
}
793
764
List <TreePath > chain = new ArrayList <>(); //TODO: avoid creating an instance if possible!
@@ -963,7 +934,7 @@ public Void visitVariable(VariableTree tree, Void p) {
963
934
964
935
tl .moveNext ();
965
936
966
- if (info .getTreeUtilities ().isVarType (getCurrentPath ()) && isJavaInlineHintVarType () ) {
937
+ if (info .getTreeUtilities ().isVarType (getCurrentPath ()) && settings . javaInlineHintVarType ) {
967
938
int afterName = tl .offset ();
968
939
TypeMirror type = info .getTrees ().getTypeMirror (new TreePath (getCurrentPath (), tree .getType ()));
969
940
@@ -1156,7 +1127,7 @@ private int leadingIndent(String line) {
1156
1127
}
1157
1128
1158
1129
private void addParameterInlineHint (Tree tree ) {
1159
- if (! isJavaInlineHintParameterName () ) {
1130
+ if (! settings . javaInlineHintParameterName ) {
1160
1131
return ;
1161
1132
}
1162
1133
TreePath pp = getCurrentPath ().getParentPath ();
@@ -1197,5 +1168,35 @@ public static interface ErrorDescriptionSetter {
1197
1168
1198
1169
public void setHighlights (Document doc , Collection <Pair <int [], Coloring >> highlights , Map <int [], String > preText );
1199
1170
public void setColorings (Document doc , Map <Token , Coloring > colorings );
1200
- }
1171
+ }
1172
+
1173
+ public static class Settings {
1174
+ private static final Map <String , Boolean > DEFAULT_VALUES ;
1175
+
1176
+ static {
1177
+ Map <String , Boolean > defaultValuesBuilder = new HashMap <>();
1178
+ defaultValuesBuilder .put (JAVA_INLINE_HINT_PARAMETER_NAME , true );
1179
+ defaultValuesBuilder .put (JAVA_INLINE_HINT_CHAINED_TYPES , false );
1180
+ defaultValuesBuilder .put (JAVA_INLINE_HINT_VAR_TYPE , false );
1181
+ DEFAULT_VALUES = Collections .unmodifiableMap (defaultValuesBuilder );
1182
+ }
1183
+
1184
+ public final boolean javaInlineHintParameterName ;
1185
+ public final boolean javaInlineHintChainedTypes ;
1186
+ public final boolean javaInlineHintVarType ;
1187
+
1188
+ public Settings (boolean javaInlineHintParameterName , boolean javaInlineHintChainedTypes , boolean javaInlineHintVarType ) {
1189
+ this .javaInlineHintParameterName = javaInlineHintParameterName ;
1190
+ this .javaInlineHintChainedTypes = javaInlineHintChainedTypes ;
1191
+ this .javaInlineHintVarType = javaInlineHintVarType ;
1192
+ }
1193
+
1194
+ public static Settings getDefault () {
1195
+ Preferences preferences = NbPreferences .root ().node ("/org/netbeans/modules/java/editor/InlineHints/default" );
1196
+ return new Settings (preferences .getBoolean (JAVA_INLINE_HINT_PARAMETER_NAME , DEFAULT_VALUES .get (JAVA_INLINE_HINT_PARAMETER_NAME )),
1197
+ preferences .getBoolean (JAVA_INLINE_HINT_CHAINED_TYPES , DEFAULT_VALUES .get (JAVA_INLINE_HINT_CHAINED_TYPES )),
1198
+ preferences .getBoolean (JAVA_INLINE_HINT_VAR_TYPE , DEFAULT_VALUES .get (JAVA_INLINE_HINT_VAR_TYPE )));
1199
+ }
1200
+
1201
+ }
1201
1202
}
0 commit comments