@@ -97,39 +97,6 @@ public abstract class SemanticHighlighterBase extends JavaParserResultTask {
9797 public static final String JAVA_INLINE_HINT_CHAINED_TYPES = "javaInlineHintChainedTypes" ; //NOI18N
9898 public static final String JAVA_INLINE_HINT_VAR_TYPE = "javaInlineHintVarType" ; //NOI18N
9999
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-
133100 private AtomicBoolean cancel = new AtomicBoolean ();
134101
135102 protected SemanticHighlighterBase () {
@@ -189,9 +156,11 @@ public Class<? extends Scheduler> getSchedulerClass() {
189156 protected abstract boolean process (CompilationInfo info , final Document doc );
190157
191158 protected boolean process (CompilationInfo info , final Document doc , ErrorDescriptionSetter setter ) {
192- updateFromPreferences ();
159+ return process (info , doc , Settings .getDefault (), setter );
160+ }
193161
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 );
195164
196165 Map <Token , Coloring > newColoring = new IdentityHashMap <>();
197166
@@ -315,8 +284,9 @@ public String toString() {
315284
316285 private static class DetectorVisitor extends CancellableTreePathScanner <Void , Void > {
317286
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 ;
320290 private Map <Element , List <Use >> type2Uses ;
321291 private Map <Tree , List <Token >> tree2Tokens ;
322292 private List <Token > contextKeywords ;
@@ -327,11 +297,12 @@ private static class DetectorVisitor extends CancellableTreePathScanner<Void, Vo
327297 private SourcePositions sourcePositions ;
328298 private ExecutableElement recursionDetector ;
329299
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 ) {
331301 super (cancel );
332302
333303 this .info = info ;
334304 this .doc = doc ;
305+ this .settings = settings ;
335306 type2Uses = new HashMap <Element , List <Use >>();
336307 tree2Tokens = new IdentityHashMap <Tree , List <Token >>();
337308 contextKeywords = new ArrayList <>();
@@ -787,7 +758,7 @@ public Void visitMethodInvocation(MethodInvocationTree tree, Void p) {
787758 }
788759
789760 private void addChainedTypes (TreePath current ) {
790- if (! isJavaInlineHintChainedTypes () ) {
761+ if (! settings . javaInlineHintChainedTypes ) {
791762 return ;
792763 }
793764 List <TreePath > chain = new ArrayList <>(); //TODO: avoid creating an instance if possible!
@@ -963,7 +934,7 @@ public Void visitVariable(VariableTree tree, Void p) {
963934
964935 tl .moveNext ();
965936
966- if (info .getTreeUtilities ().isVarType (getCurrentPath ()) && isJavaInlineHintVarType () ) {
937+ if (info .getTreeUtilities ().isVarType (getCurrentPath ()) && settings . javaInlineHintVarType ) {
967938 int afterName = tl .offset ();
968939 TypeMirror type = info .getTrees ().getTypeMirror (new TreePath (getCurrentPath (), tree .getType ()));
969940
@@ -1156,7 +1127,7 @@ private int leadingIndent(String line) {
11561127 }
11571128
11581129 private void addParameterInlineHint (Tree tree ) {
1159- if (! isJavaInlineHintParameterName () ) {
1130+ if (! settings . javaInlineHintParameterName ) {
11601131 return ;
11611132 }
11621133 TreePath pp = getCurrentPath ().getParentPath ();
@@ -1197,5 +1168,35 @@ public static interface ErrorDescriptionSetter {
11971168
11981169 public void setHighlights (Document doc , Collection <Pair <int [], Coloring >> highlights , Map <int [], String > preText );
11991170 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+ }
12011202}
0 commit comments