1 /*******************************************************************************
2  * Copyright (c) 2000, 2020 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *     Andre Soereng <andreis@fast.no> - [syntax highlighting] highlight numbers - https://bugs.eclipse.org/bugs/show_bug.cgi?id=63573
14  *     Björn Michael <b.michael@gmx.de> - [syntax highlighting] Syntax coloring for abstract classes - https://bugs.eclipse.org/331311
15  *     Björn Michael <b.michael@gmx.de> - [syntax highlighting] Add highlight for inherited fields - https://bugs.eclipse.org/348368
16  *******************************************************************************/
17 package org.eclipse.jdt.internal.ui.javaeditor;
18 
19 import org.eclipse.swt.graphics.RGB;
20 
21 import org.eclipse.jface.preference.IPreferenceStore;
22 import org.eclipse.jface.preference.PreferenceConverter;
23 import org.eclipse.jface.util.PropertyChangeEvent;
24 
25 import org.eclipse.jdt.core.dom.ASTNode;
26 import org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration;
27 import org.eclipse.jdt.core.dom.ArrayAccess;
28 import org.eclipse.jdt.core.dom.CastExpression;
29 import org.eclipse.jdt.core.dom.ClassInstanceCreation;
30 import org.eclipse.jdt.core.dom.ConditionalExpression;
31 import org.eclipse.jdt.core.dom.Expression;
32 import org.eclipse.jdt.core.dom.FieldDeclaration;
33 import org.eclipse.jdt.core.dom.IBinding;
34 import org.eclipse.jdt.core.dom.IMethodBinding;
35 import org.eclipse.jdt.core.dom.ITypeBinding;
36 import org.eclipse.jdt.core.dom.IVariableBinding;
37 import org.eclipse.jdt.core.dom.InfixExpression;
38 import org.eclipse.jdt.core.dom.MemberValuePair;
39 import org.eclipse.jdt.core.dom.MethodDeclaration;
40 import org.eclipse.jdt.core.dom.Modifier;
41 import org.eclipse.jdt.core.dom.NameQualifiedType;
42 import org.eclipse.jdt.core.dom.ParameterizedType;
43 import org.eclipse.jdt.core.dom.PrefixExpression;
44 import org.eclipse.jdt.core.dom.QualifiedName;
45 import org.eclipse.jdt.core.dom.SimpleName;
46 import org.eclipse.jdt.core.dom.SimpleType;
47 import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
48 import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor;
49 import org.eclipse.jdt.core.dom.VariableDeclaration;
50 import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
51 
52 import org.eclipse.jdt.internal.corext.dom.ASTNodes;
53 import org.eclipse.jdt.internal.corext.dom.Bindings;
54 
55 import org.eclipse.jdt.ui.PreferenceConstants;
56 
57 import org.eclipse.jdt.internal.ui.preferences.PreferencesMessages;
58 
59 	/**
60  * Semantic highlightings
61  *
62  * @since 3.0
63  */
64 public class SemanticHighlightings {
65 
66 	/**
67 	 * A named preference part that controls the highlighting of static final fields.
68 	 */
69 	public static final String STATIC_FINAL_FIELD= SemanticHighlightingsCore.STATIC_FINAL_FIELD;
70 
71 	/**
72 	 * A named preference part that controls the highlighting of static fields.
73 	 */
74 	public static final String STATIC_FIELD= SemanticHighlightingsCore.STATIC_FIELD;
75 
76 	/**
77 	 * A named preference part that controls the highlighting of fields.
78 	 */
79 	public static final String FIELD= SemanticHighlightingsCore.FIELD;
80 
81 	/**
82 	 * A named preference part that controls the highlighting of method declarations.
83 	 */
84 	public static final String METHOD_DECLARATION= SemanticHighlightingsCore.METHOD_DECLARATION;
85 
86 	/**
87 	 * A named preference part that controls the highlighting of static method invocations.
88 	 */
89 	public static final String STATIC_METHOD_INVOCATION= SemanticHighlightingsCore.STATIC_METHOD_INVOCATION;
90 
91 	/**
92 	 * A named preference part that controls the highlighting of inherited method invocations.
93 	 */
94 	public static final String INHERITED_METHOD_INVOCATION= SemanticHighlightingsCore.INHERITED_METHOD_INVOCATION;
95 
96 	/**
97 	 * A named preference part that controls the highlighting of annotation element references.
98 	 * @since 3.1
99 	 */
100 	public static final String ANNOTATION_ELEMENT_REFERENCE= SemanticHighlightingsCore.ANNOTATION_ELEMENT_REFERENCE;
101 
102 	/**
103 	 * A named preference part that controls the highlighting of abstract method invocations.
104 	 */
105 	public static final String ABSTRACT_METHOD_INVOCATION= SemanticHighlightingsCore.ABSTRACT_METHOD_INVOCATION;
106 
107 	/**
108 	 * A named preference part that controls the highlighting of local variables.
109 	 */
110 	public static final String LOCAL_VARIABLE_DECLARATION= SemanticHighlightingsCore.LOCAL_VARIABLE_DECLARATION;
111 
112 	/**
113 	 * A named preference part that controls the highlighting of local variables.
114 	 */
115 	public static final String LOCAL_VARIABLE= SemanticHighlightingsCore.LOCAL_VARIABLE;
116 
117 	/**
118 	 * A named preference part that controls the highlighting of parameter variables.
119 	 */
120 	public static final String PARAMETER_VARIABLE= SemanticHighlightingsCore.PARAMETER_VARIABLE;
121 
122 	/**
123 	 * A named preference part that controls the highlighting of deprecated members.
124 	 */
125 	public static final String DEPRECATED_MEMBER= SemanticHighlightingsCore.DEPRECATED_MEMBER;
126 
127 	/**
128 	 * A named preference part that controls the highlighting of type parameters.
129 	 * @since 3.1
130 	 */
131 	public static final String TYPE_VARIABLE= SemanticHighlightingsCore.TYPE_VARIABLE;
132 
133 	/**
134 	 * A named preference part that controls the highlighting of methods
135 	 * (invocations and declarations).
136 	 *
137 	 * @since 3.1
138 	 */
139 	public static final String METHOD= SemanticHighlightingsCore.METHOD;
140 
141 	/**
142 	 * A named preference part that controls the highlighting of auto(un)boxed
143 	 * expressions.
144 	 *
145 	 * @since 3.1
146 	 */
147 	public static final String AUTOBOXING= SemanticHighlightingsCore.AUTOBOXING;
148 
149 	/**
150 	 * A named preference part that controls the highlighting of classes.
151 	 *
152 	 * @since 3.2
153 	 */
154 	public static final String CLASS= SemanticHighlightingsCore.CLASS;
155 
156 	/**
157 	 * A named preference part that controls the highlighting of enums.
158 	 *
159 	 * @since 3.2
160 	 */
161 	public static final String ENUM= SemanticHighlightingsCore.ENUM;
162 
163 	/**
164 	 * A named preference part that controls the highlighting of interfaces.
165 	 *
166 	 * @since 3.2
167 	 */
168 	public static final String INTERFACE= SemanticHighlightingsCore.INTERFACE;
169 
170 	/**
171 	 * A named preference part that controls the highlighting of annotations.
172 	 *
173 	 * @since 3.2
174 	 */
175 	public static final String ANNOTATION= SemanticHighlightingsCore.ANNOTATION;
176 
177 	/**
178 	 * A named preference part that controls the highlighting of type arguments.
179 	 *
180 	 * @since 3.2
181 	 */
182 	public static final String TYPE_ARGUMENT= SemanticHighlightingsCore.TYPE_ARGUMENT;
183 
184 	/**
185 	 * A named preference part that controls the highlighting of numbers.
186 	 *
187 	 * @since 3.4
188 	 */
189 	public static final String NUMBER= SemanticHighlightingsCore.NUMBER;
190 
191 	/**
192 	 * A named preference part that controls the highlighting of abstract classes.
193 	 *
194 	 * @since 3.7
195 	 */
196 	public static final String ABSTRACT_CLASS= SemanticHighlightingsCore.ABSTRACT_CLASS;
197 
198 	/**
199 	 * A named preference part that controls the highlighting of inherited fields.
200 	 *
201 	 * @since 3.8
202 	 */
203 	public static final String INHERITED_FIELD= SemanticHighlightingsCore.INHERITED_FIELD;
204 
205 	/**
206 	 * A named preference part that controls the highlighting of 'var' keywords.
207 	 */
208 	public static final String VAR_KEYWORD= SemanticHighlightingsCore.VAR_KEYWORD;
209 
210 	/**
211 	 * A named preference part that controls the highlighting of 'yield' keywords.
212 	 */
213 	public static final String YIELD_KEYWORD= SemanticHighlightingsCore.YIELD_KEYWORD;
214 
215 	/**
216 	 * A named preference part that controls the highlighting of 'record' keywords.
217 	 */
218 	public static final String RECORD_KEYWORD= SemanticHighlightingsCore.RECORD_KEYWORD;
219 
220 	/**
221 	 * Semantic highlightings
222 	 */
223 	private static SemanticHighlighting[] fgSemanticHighlightings;
224 
225 	/**
226 	 * Semantic highlighting for static final fields.
227 	 */
228 	private static final class StaticFinalFieldHighlighting extends SemanticHighlighting {
229 
230 		/*
231 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
232 		 */
233 		@Override
getPreferenceKey()234 		public String getPreferenceKey() {
235 			return STATIC_FINAL_FIELD;
236 		}
237 
238 		/*
239 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
240 		 */
241 		@Override
getDefaultDefaultTextColor()242 		public RGB getDefaultDefaultTextColor() {
243 			return new RGB(0, 0, 192);
244 		}
245 
246 		/*
247 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
248 		 */
249 		@Override
isBoldByDefault()250 		public boolean isBoldByDefault() {
251 			return true;
252 		}
253 
254 		/*
255 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
256 		 */
257 		@Override
isItalicByDefault()258 		public boolean isItalicByDefault() {
259 			return true;
260 		}
261 
262 		/*
263 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
264 		 */
265 		@Override
isEnabledByDefault()266 		public boolean isEnabledByDefault() {
267 			return true;
268 		}
269 
270 		/*
271 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
272 		 */
273 		@Override
getDisplayName()274 		public String getDisplayName() {
275 			return JavaEditorMessages.SemanticHighlighting_staticFinalField;
276 		}
277 
278 		/*
279 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
280 		 */
281 		@Override
consumes(SemanticToken token)282 		public boolean consumes(SemanticToken token) {
283 			IBinding binding= token.getBinding();
284 			return binding != null && binding.getKind() == IBinding.VARIABLE && ((IVariableBinding)binding).isField() && (binding.getModifiers() & (Modifier.FINAL | Modifier.STATIC)) == (Modifier.FINAL | Modifier.STATIC);
285 		}
286 	}
287 
288 	/**
289 	 * Semantic highlighting for static fields.
290 	 */
291 	private static final class StaticFieldHighlighting extends SemanticHighlighting {
292 
293 		/*
294 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
295 		 */
296 		@Override
getPreferenceKey()297 		public String getPreferenceKey() {
298 			return STATIC_FIELD;
299 		}
300 
301 		/*
302 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
303 		 */
304 		@Override
getDefaultDefaultTextColor()305 		public RGB getDefaultDefaultTextColor() {
306 			return new RGB(0, 0, 192);
307 		}
308 
309 		/*
310 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
311 		 */
312 		@Override
isBoldByDefault()313 		public boolean isBoldByDefault() {
314 			return false;
315 		}
316 
317 		/*
318 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
319 		 */
320 		@Override
isItalicByDefault()321 		public boolean isItalicByDefault() {
322 			return true;
323 		}
324 
325 		/*
326 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
327 		 */
328 		@Override
isEnabledByDefault()329 		public boolean isEnabledByDefault() {
330 			return true;
331 		}
332 
333 		/*
334 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
335 		 */
336 		@Override
getDisplayName()337 		public String getDisplayName() {
338 			return JavaEditorMessages.SemanticHighlighting_staticField;
339 		}
340 
341 		/*
342 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
343 		 */
344 		@Override
consumes(SemanticToken token)345 		public boolean consumes(SemanticToken token) {
346 			IBinding binding= token.getBinding();
347 			return binding != null && binding.getKind() == IBinding.VARIABLE && ((IVariableBinding)binding).isField() && (binding.getModifiers() & Modifier.STATIC) == Modifier.STATIC;
348 		}
349 	}
350 
351 	/**
352 	 * Semantic highlighting for fields.
353 	 */
354 	private static final class FieldHighlighting extends SemanticHighlighting {
355 
356 		/*
357 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
358 		 */
359 		@Override
getPreferenceKey()360 		public String getPreferenceKey() {
361 			return FIELD;
362 		}
363 
364 		/*
365 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
366 		 */
367 		@Override
getDefaultDefaultTextColor()368 		public RGB getDefaultDefaultTextColor() {
369 			return new RGB(0, 0, 192);
370 		}
371 
372 		/*
373 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
374 		 */
375 		@Override
isBoldByDefault()376 		public boolean isBoldByDefault() {
377 			return false;
378 		}
379 
380 		/*
381 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
382 		 */
383 		@Override
isItalicByDefault()384 		public boolean isItalicByDefault() {
385 			return false;
386 		}
387 
388 		/*
389 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
390 		 */
391 		@Override
isEnabledByDefault()392 		public boolean isEnabledByDefault() {
393 			return true;
394 		}
395 
396 		/*
397 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
398 		 */
399 		@Override
getDisplayName()400 		public String getDisplayName() {
401 			return JavaEditorMessages.SemanticHighlighting_field;
402 		}
403 
404 		/*
405 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
406 		 */
407 		@Override
consumes(SemanticToken token)408 		public boolean consumes(SemanticToken token) {
409 			IBinding binding= token.getBinding();
410 			return binding != null && binding.getKind() == IBinding.VARIABLE && ((IVariableBinding)binding).isField();
411 		}
412 	}
413 
414 	/**
415 	 * Semantic highlighting for auto(un)boxed expressions.
416 	 */
417 	private static final class AutoboxHighlighting extends SemanticHighlighting {
418 
419 		/*
420 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
421 		 */
422 		@Override
getPreferenceKey()423 		public String getPreferenceKey() {
424 			return AUTOBOXING;
425 		}
426 
427 		/*
428 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
429 		 */
430 		@Override
getDefaultDefaultTextColor()431 		public RGB getDefaultDefaultTextColor() {
432 			return new RGB(171, 48, 0);
433 		}
434 
435 		/*
436 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
437 		 */
438 		@Override
isBoldByDefault()439 		public boolean isBoldByDefault() {
440 			return false;
441 		}
442 
443 		/*
444 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
445 		 */
446 		@Override
isItalicByDefault()447 		public boolean isItalicByDefault() {
448 			return false;
449 		}
450 
451 		/*
452 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
453 		 */
454 		@Override
isEnabledByDefault()455 		public boolean isEnabledByDefault() {
456 			return false;
457 		}
458 
459 		/*
460 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
461 		 */
462 		@Override
getDisplayName()463 		public String getDisplayName() {
464 			return JavaEditorMessages.SemanticHighlighting_autoboxing;
465 		}
466 
467 		/*
468 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumesLiteral(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
469 		 */
470 		@Override
consumesLiteral(SemanticToken token)471 		public boolean consumesLiteral(SemanticToken token) {
472 			return isAutoUnBoxing(token.getLiteral());
473 		}
474 
475 		/*
476 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
477 		 */
478 		@Override
consumes(SemanticToken token)479 		public boolean consumes(SemanticToken token) {
480 			return isAutoUnBoxing(token.getNode());
481 		}
482 
isAutoUnBoxing(Expression node)483 		private boolean isAutoUnBoxing(Expression node) {
484 			if (isAutoUnBoxingExpression(node))
485 				return true;
486 			// special cases: the autoboxing conversions happens at a
487 			// location that is not mapped directly to a simple name
488 			// or a literal, but can still be mapped somehow
489 			// A) expressions
490 			StructuralPropertyDescriptor desc= node.getLocationInParent();
491 			if (desc == ArrayAccess.ARRAY_PROPERTY
492 					|| desc == InfixExpression.LEFT_OPERAND_PROPERTY
493 					|| desc == InfixExpression.RIGHT_OPERAND_PROPERTY
494 					|| desc == ConditionalExpression.THEN_EXPRESSION_PROPERTY
495 					|| desc == PrefixExpression.OPERAND_PROPERTY
496 					|| desc == CastExpression.EXPRESSION_PROPERTY
497 					|| desc == ConditionalExpression.ELSE_EXPRESSION_PROPERTY) {
498 				ASTNode parent= node.getParent();
499 				if (parent instanceof Expression)
500 					return isAutoUnBoxingExpression((Expression) parent);
501 			}
502 			// B) constructor invocations
503 			if (desc == QualifiedName.NAME_PROPERTY) {
504 				node= (Expression) node.getParent();
505 				desc= node.getLocationInParent();
506 			}
507 			if (desc == SimpleType.NAME_PROPERTY || desc == NameQualifiedType.NAME_PROPERTY) {
508 				ASTNode parent= node.getParent();
509 				if (parent != null && parent.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY) {
510 					parent= parent.getParent();
511 					return isAutoUnBoxingExpression((ClassInstanceCreation) parent);
512 				}
513 			}
514 			return false;
515 		}
516 
isAutoUnBoxingExpression(Expression expression)517 		private boolean isAutoUnBoxingExpression(Expression expression) {
518 			return expression.resolveBoxing() || expression.resolveUnboxing();
519 		}
520 	}
521 
522 	/**
523 	 * Semantic highlighting for method declarations.
524 	 */
525 	private static final class MethodDeclarationHighlighting extends SemanticHighlighting {
526 
527 		/*
528 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
529 		 */
530 		@Override
getPreferenceKey()531 		public String getPreferenceKey() {
532 			return METHOD_DECLARATION;
533 		}
534 
535 		/*
536 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
537 		 */
538 		@Override
getDefaultDefaultTextColor()539 		public RGB getDefaultDefaultTextColor() {
540 			return new RGB(0, 0, 0);
541 		}
542 
543 		/*
544 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
545 		 */
546 		@Override
isBoldByDefault()547 		public boolean isBoldByDefault() {
548 			return true;
549 		}
550 
551 		/*
552 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
553 		 */
554 		@Override
isItalicByDefault()555 		public boolean isItalicByDefault() {
556 			return false;
557 		}
558 
559 		/*
560 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
561 		 */
562 		@Override
isEnabledByDefault()563 		public boolean isEnabledByDefault() {
564 			return false;
565 		}
566 
567 		/*
568 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
569 		 */
570 		@Override
getDisplayName()571 		public String getDisplayName() {
572 			return JavaEditorMessages.SemanticHighlighting_methodDeclaration;
573 		}
574 
575 		/*
576 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#isMatched(org.eclipse.jdt.core.dom.ASTNode)
577 		 */
578 		@Override
consumes(SemanticToken token)579 		public boolean consumes(SemanticToken token) {
580 			StructuralPropertyDescriptor location= token.getNode().getLocationInParent();
581 			return location == MethodDeclaration.NAME_PROPERTY || location == AnnotationTypeMemberDeclaration.NAME_PROPERTY;
582 		}
583 	}
584 
585 	/**
586 	 * Semantic highlighting for static method invocations.
587 	 */
588 	private static final class StaticMethodInvocationHighlighting extends SemanticHighlighting {
589 
590 		/*
591 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
592 		 */
593 		@Override
getPreferenceKey()594 		public String getPreferenceKey() {
595 			return STATIC_METHOD_INVOCATION;
596 		}
597 
598 		/*
599 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
600 		 */
601 		@Override
getDefaultDefaultTextColor()602 		public RGB getDefaultDefaultTextColor() {
603 			return new RGB(0, 0, 0);
604 		}
605 
606 		/*
607 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
608 		 */
609 		@Override
isBoldByDefault()610 		public boolean isBoldByDefault() {
611 			return false;
612 		}
613 
614 		/*
615 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
616 		 */
617 		@Override
isItalicByDefault()618 		public boolean isItalicByDefault() {
619 			return true;
620 		}
621 
622 		/*
623 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
624 		 */
625 		@Override
isEnabledByDefault()626 		public boolean isEnabledByDefault() {
627 			return true;
628 		}
629 
630 		/*
631 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
632 		 */
633 		@Override
getDisplayName()634 		public String getDisplayName() {
635 			return JavaEditorMessages.SemanticHighlighting_staticMethodInvocation;
636 		}
637 
638 		/*
639 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#isMatched(org.eclipse.jdt.core.dom.ASTNode)
640 		 */
641 		@Override
consumes(SemanticToken token)642 		public boolean consumes(SemanticToken token) {
643 			SimpleName node= token.getNode();
644 			if (node.isDeclaration())
645 				return false;
646 
647 			IBinding binding= token.getBinding();
648 			return binding != null && binding.getKind() == IBinding.METHOD && (binding.getModifiers() & Modifier.STATIC) == Modifier.STATIC;
649 		}
650 	}
651 
652 	/**
653 	 * Semantic highlighting for annotation element references.
654 	 * @since 3.1
655 	 */
656 	private static final class AnnotationElementReferenceHighlighting extends SemanticHighlighting {
657 
658 		/*
659 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
660 		 */
661 		@Override
getPreferenceKey()662 		public String getPreferenceKey() {
663 			return ANNOTATION_ELEMENT_REFERENCE;
664 		}
665 
666 		/*
667 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
668 		 */
669 		@Override
getDefaultDefaultTextColor()670 		public RGB getDefaultDefaultTextColor() {
671 			return new RGB(0, 0, 0);
672 		}
673 
674 		/*
675 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
676 		 */
677 		@Override
isBoldByDefault()678 		public boolean isBoldByDefault() {
679 			return false;
680 		}
681 
682 		/*
683 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
684 		 */
685 		@Override
isItalicByDefault()686 		public boolean isItalicByDefault() {
687 			return false;
688 		}
689 
690 		/*
691 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
692 		 */
693 		@Override
isEnabledByDefault()694 		public boolean isEnabledByDefault() {
695 			return false;
696 		}
697 
698 		/*
699 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
700 		 */
701 		@Override
getDisplayName()702 		public String getDisplayName() {
703 			return JavaEditorMessages.SemanticHighlighting_annotationElementReference;
704 		}
705 
706 		/*
707 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#isMatched(org.eclipse.jdt.core.dom.ASTNode)
708 		 */
709 		@Override
consumes(SemanticToken token)710 		public boolean consumes(SemanticToken token) {
711 			SimpleName node= token.getNode();
712 			if (node.getParent() instanceof MemberValuePair) {
713 				IBinding binding= token.getBinding();
714 				boolean isAnnotationElement= binding != null && binding.getKind() == IBinding.METHOD;
715 
716 				return isAnnotationElement;
717 			}
718 
719 			return false;
720 		}
721 	}
722 
723 	/**
724 	 * Semantic highlighting for abstract method invocations.
725 	 */
726 	private static final class AbstractMethodInvocationHighlighting extends SemanticHighlighting {
727 
728 		/*
729 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
730 		 */
731 		@Override
getPreferenceKey()732 		public String getPreferenceKey() {
733 			return ABSTRACT_METHOD_INVOCATION;
734 		}
735 
736 		/*
737 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
738 		 */
739 		@Override
getDefaultDefaultTextColor()740 		public RGB getDefaultDefaultTextColor() {
741 			return new RGB(0, 0, 0);
742 		}
743 
744 		/*
745 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
746 		 */
747 		@Override
isBoldByDefault()748 		public boolean isBoldByDefault() {
749 			return false;
750 		}
751 
752 		/*
753 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
754 		 */
755 		@Override
isItalicByDefault()756 		public boolean isItalicByDefault() {
757 			return false;
758 		}
759 
760 		/*
761 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
762 		 */
763 		@Override
isEnabledByDefault()764 		public boolean isEnabledByDefault() {
765 			return false;
766 		}
767 
768 		/*
769 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
770 		 */
771 		@Override
getDisplayName()772 		public String getDisplayName() {
773 			return JavaEditorMessages.SemanticHighlighting_abstractMethodInvocation;
774 		}
775 
776 		/*
777 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#isMatched(org.eclipse.jdt.core.dom.ASTNode)
778 		 */
779 		@Override
consumes(SemanticToken token)780 		public boolean consumes(SemanticToken token) {
781 			SimpleName node= token.getNode();
782 			if (node.isDeclaration())
783 				return false;
784 
785 			IBinding binding= token.getBinding();
786 			boolean isAbstractMethod= binding != null && binding.getKind() == IBinding.METHOD && (binding.getModifiers() & Modifier.ABSTRACT) == Modifier.ABSTRACT;
787 			if (!isAbstractMethod)
788 				return false;
789 
790 			// filter out annotation value references
791 			if (binding != null) {
792 				ITypeBinding declaringType= ((IMethodBinding)binding).getDeclaringClass();
793 				if (declaringType.isAnnotation())
794 					return false;
795 			}
796 
797 			return true;
798 		}
799 	}
800 
801 	/**
802 	 * Semantic highlighting for inherited method invocations.
803 	 */
804 	private static final class InheritedMethodInvocationHighlighting extends SemanticHighlighting {
805 
806 		/*
807 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
808 		 */
809 		@Override
getPreferenceKey()810 		public String getPreferenceKey() {
811 			return INHERITED_METHOD_INVOCATION;
812 		}
813 
814 		/*
815 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
816 		 */
817 		@Override
getDefaultDefaultTextColor()818 		public RGB getDefaultDefaultTextColor() {
819 			return new RGB(0, 0, 0);
820 		}
821 
822 		/*
823 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
824 		 */
825 		@Override
isBoldByDefault()826 		public boolean isBoldByDefault() {
827 			return false;
828 		}
829 
830 		/*
831 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
832 		 */
833 		@Override
isItalicByDefault()834 		public boolean isItalicByDefault() {
835 			return false;
836 		}
837 
838 		/*
839 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
840 		 */
841 		@Override
isEnabledByDefault()842 		public boolean isEnabledByDefault() {
843 			return false;
844 		}
845 
846 		/*
847 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
848 		 */
849 		@Override
getDisplayName()850 		public String getDisplayName() {
851 			return JavaEditorMessages.SemanticHighlighting_inheritedMethodInvocation;
852 		}
853 
854 		/*
855 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#isMatched(org.eclipse.jdt.core.dom.ASTNode)
856 		 */
857 		@Override
consumes(SemanticToken token)858 		public boolean consumes(SemanticToken token) {
859 			SimpleName node= token.getNode();
860 			if (node.isDeclaration())
861 				return false;
862 
863 			IBinding binding= token.getBinding();
864 			if (binding == null || binding.getKind() != IBinding.METHOD)
865 				return false;
866 
867 			ITypeBinding currentType= Bindings.getBindingOfParentType(node);
868 			ITypeBinding declaringType= ((IMethodBinding) binding).getDeclaringClass();
869 			if (currentType == declaringType || currentType == null)
870 				return false;
871 
872 			return Bindings.isSuperType(declaringType, currentType);
873 		}
874 	}
875 
876 	/**
877 	 * Semantic highlighting for inherited method invocations.
878 	 */
879 	private static final class MethodHighlighting extends SemanticHighlighting {
880 
881 		/*
882 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
883 		 */
884 		@Override
getPreferenceKey()885 		public String getPreferenceKey() {
886 			return METHOD;
887 		}
888 
889 		/*
890 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
891 		 */
892 		@Override
getDefaultDefaultTextColor()893 		public RGB getDefaultDefaultTextColor() {
894 			return new RGB(0, 0, 0);
895 		}
896 
897 		/*
898 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
899 		 */
900 		@Override
isBoldByDefault()901 		public boolean isBoldByDefault() {
902 			return false;
903 		}
904 
905 		/*
906 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
907 		 */
908 		@Override
isItalicByDefault()909 		public boolean isItalicByDefault() {
910 			return false;
911 		}
912 
913 		/*
914 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
915 		 */
916 		@Override
isEnabledByDefault()917 		public boolean isEnabledByDefault() {
918 			return false;
919 		}
920 
921 		/*
922 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
923 		 */
924 		@Override
getDisplayName()925 		public String getDisplayName() {
926 			return JavaEditorMessages.SemanticHighlighting_method;
927 		}
928 
929 		/*
930 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#isMatched(org.eclipse.jdt.core.dom.ASTNode)
931 		 */
932 		@Override
consumes(SemanticToken token)933 		public boolean consumes(SemanticToken token) {
934 			IBinding binding= getBinding(token);
935 			return binding != null && binding.getKind() == IBinding.METHOD;
936 		}
937 	}
938 
939 	/**
940 	 * Semantic highlighting for local variable declarations.
941 	 */
942 	private static final class LocalVariableDeclarationHighlighting extends SemanticHighlighting {
943 
944 		/*
945 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
946 		 */
947 		@Override
getPreferenceKey()948 		public String getPreferenceKey() {
949 			return LOCAL_VARIABLE_DECLARATION;
950 		}
951 
952 		/*
953 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
954 		 */
955 		@Override
getDefaultDefaultTextColor()956 		public RGB getDefaultDefaultTextColor() {
957 			return new RGB(106, 62, 62);
958 		}
959 
960 		/*
961 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
962 		 */
963 		@Override
isBoldByDefault()964 		public boolean isBoldByDefault() {
965 			return true;
966 		}
967 
968 		/*
969 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
970 		 */
971 		@Override
isItalicByDefault()972 		public boolean isItalicByDefault() {
973 			return false;
974 		}
975 
976 		/*
977 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
978 		 */
979 		@Override
isEnabledByDefault()980 		public boolean isEnabledByDefault() {
981 			return false;
982 		}
983 
984 		/*
985 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
986 		 */
987 		@Override
getDisplayName()988 		public String getDisplayName() {
989 			return JavaEditorMessages.SemanticHighlighting_localVariableDeclaration;
990 		}
991 
992 		/*
993 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
994 		 */
995 		@Override
consumes(SemanticToken token)996 		public boolean consumes(SemanticToken token) {
997 			SimpleName node= token.getNode();
998 			StructuralPropertyDescriptor location= node.getLocationInParent();
999 			if (location == VariableDeclarationFragment.NAME_PROPERTY || location == SingleVariableDeclaration.NAME_PROPERTY) {
1000 				ASTNode parent= node.getParent();
1001 				if (parent instanceof VariableDeclaration) {
1002 					parent= parent.getParent();
1003 					return parent == null || !(parent instanceof FieldDeclaration);
1004 				}
1005 			}
1006 			return false;
1007 		}
1008 	}
1009 
1010 	/**
1011 	 * Semantic highlighting for local variables.
1012 	 */
1013 	private static final class LocalVariableHighlighting extends SemanticHighlighting {
1014 
1015 		/*
1016 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
1017 		 */
1018 		@Override
getPreferenceKey()1019 		public String getPreferenceKey() {
1020 			return LOCAL_VARIABLE;
1021 		}
1022 
1023 		/*
1024 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
1025 		 */
1026 		@Override
getDefaultDefaultTextColor()1027 		public RGB getDefaultDefaultTextColor() {
1028 			return new RGB(106, 62, 62);
1029 		}
1030 
1031 		/*
1032 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
1033 		 */
1034 		@Override
isBoldByDefault()1035 		public boolean isBoldByDefault() {
1036 			return false;
1037 		}
1038 
1039 		/*
1040 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
1041 		 */
1042 		@Override
isItalicByDefault()1043 		public boolean isItalicByDefault() {
1044 			return false;
1045 		}
1046 
1047 		/*
1048 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
1049 		 */
1050 		@Override
isEnabledByDefault()1051 		public boolean isEnabledByDefault() {
1052 			return true;
1053 		}
1054 
1055 		/*
1056 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
1057 		 */
1058 		@Override
getDisplayName()1059 		public String getDisplayName() {
1060 			return JavaEditorMessages.SemanticHighlighting_localVariable;
1061 		}
1062 
1063 		/*
1064 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
1065 		 */
1066 		@Override
consumes(SemanticToken token)1067 		public boolean consumes(SemanticToken token) {
1068 			IBinding binding= token.getBinding();
1069 			if (binding != null && binding.getKind() == IBinding.VARIABLE && !((IVariableBinding) binding).isField()) {
1070 				ASTNode decl= token.getRoot().findDeclaringNode(binding);
1071 				return decl instanceof VariableDeclaration;
1072 			}
1073 			return false;
1074 		}
1075 	}
1076 
1077 	/**
1078 	 * Semantic highlighting for parameter variables.
1079 	 */
1080 	private static final class ParameterVariableHighlighting extends SemanticHighlighting {
1081 
1082 		/*
1083 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
1084 		 */
1085 		@Override
getPreferenceKey()1086 		public String getPreferenceKey() {
1087 			return PARAMETER_VARIABLE;
1088 		}
1089 
1090 		/*
1091 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
1092 		 */
1093 		@Override
getDefaultDefaultTextColor()1094 		public RGB getDefaultDefaultTextColor() {
1095 			return new RGB(106, 62, 62);
1096 		}
1097 
1098 		/*
1099 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
1100 		 */
1101 		@Override
isBoldByDefault()1102 		public boolean isBoldByDefault() {
1103 			return false;
1104 		}
1105 
1106 		/*
1107 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
1108 		 */
1109 		@Override
isItalicByDefault()1110 		public boolean isItalicByDefault() {
1111 			return false;
1112 		}
1113 
1114 		/*
1115 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
1116 		 */
1117 		@Override
isEnabledByDefault()1118 		public boolean isEnabledByDefault() {
1119 			return false;
1120 		}
1121 
1122 		/*
1123 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
1124 		 */
1125 		@Override
getDisplayName()1126 		public String getDisplayName() {
1127 			return JavaEditorMessages.SemanticHighlighting_parameterVariable;
1128 		}
1129 
1130 		/*
1131 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
1132 		 */
1133 		@Override
consumes(SemanticToken token)1134 		public boolean consumes(SemanticToken token) {
1135 			IBinding binding= token.getBinding();
1136 			if (binding != null && binding.getKind() == IBinding.VARIABLE && !((IVariableBinding) binding).isField()) {
1137 				ASTNode decl= token.getRoot().findDeclaringNode(binding);
1138 				return decl != null && decl.getLocationInParent() == MethodDeclaration.PARAMETERS_PROPERTY;
1139 			}
1140 			return false;
1141 		}
1142 	}
1143 
1144 	/**
1145 	 * Semantic highlighting for deprecated members.
1146 	 */
1147 	static final class DeprecatedMemberHighlighting extends SemanticHighlighting {
1148 
1149 		/*
1150 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
1151 		 */
1152 		@Override
getPreferenceKey()1153 		public String getPreferenceKey() {
1154 			return DEPRECATED_MEMBER;
1155 		}
1156 
1157 		/*
1158 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
1159 		 */
1160 		@Override
getDefaultDefaultTextColor()1161 		public RGB getDefaultDefaultTextColor() {
1162 			return new RGB(0, 0, 0);
1163 		}
1164 
1165 		/*
1166 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
1167 		 */
1168 		@Override
isBoldByDefault()1169 		public boolean isBoldByDefault() {
1170 			return false;
1171 		}
1172 
1173 		/*
1174 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
1175 		 */
1176 		@Override
isItalicByDefault()1177 		public boolean isItalicByDefault() {
1178 			return false;
1179 		}
1180 
1181 		/*
1182 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isStrikethroughByDefault()
1183 		 * @since 3.1
1184 		 */
1185 		@Override
isStrikethroughByDefault()1186 		public boolean isStrikethroughByDefault() {
1187 			return true;
1188 		}
1189 
1190 		/*
1191 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
1192 		 */
1193 		@Override
isEnabledByDefault()1194 		public boolean isEnabledByDefault() {
1195 			return true;
1196 		}
1197 
1198 		/*
1199 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
1200 		 */
1201 		@Override
getDisplayName()1202 		public String getDisplayName() {
1203 			return JavaEditorMessages.SemanticHighlighting_deprecatedMember;
1204 		}
1205 
1206 		/*
1207 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
1208 		 */
1209 		@Override
consumes(SemanticToken token)1210 		public boolean consumes(SemanticToken token) {
1211 			IBinding binding= getBinding(token);
1212 			if (binding != null) {
1213 				if (binding.isDeprecated())
1214 					return true;
1215 				if (binding instanceof IMethodBinding) {
1216 					IMethodBinding methodBinding= (IMethodBinding) binding;
1217 					ITypeBinding declaringClass= methodBinding.getDeclaringClass();
1218 					if (declaringClass == null)
1219 						return false;
1220 					if (declaringClass.isAnonymous()) {
1221 						ITypeBinding[] interfaces= declaringClass.getInterfaces();
1222 						if (interfaces.length > 0)
1223 							return interfaces[0].isDeprecated();
1224 						else
1225 							return declaringClass.getSuperclass().isDeprecated();
1226 					}
1227 					return declaringClass.isDeprecated() && !(token.getNode().getParent() instanceof MethodDeclaration);
1228 				} else if (binding instanceof IVariableBinding) {
1229 					IVariableBinding variableBinding= (IVariableBinding) binding;
1230 					ITypeBinding declaringClass= variableBinding.getDeclaringClass();
1231 					return declaringClass != null && declaringClass.isDeprecated() && !(token.getNode().getParent() instanceof VariableDeclaration);
1232 				}
1233 			}
1234 			return false;
1235 		}
1236 	}
1237 
1238 	/**
1239 	 * Semantic highlighting for type variables.
1240 	 * @since 3.1
1241 	 */
1242 	private static final class TypeVariableHighlighting extends SemanticHighlighting {
1243 
1244 		/*
1245 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
1246 		 */
1247 		@Override
getPreferenceKey()1248 		public String getPreferenceKey() {
1249 			return TYPE_VARIABLE;
1250 		}
1251 
1252 		/*
1253 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
1254 		 */
1255 		@Override
getDefaultDefaultTextColor()1256 		public RGB getDefaultDefaultTextColor() {
1257 			return new RGB(100, 70, 50);
1258 		}
1259 
1260 		/*
1261 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
1262 		 */
1263 		@Override
isBoldByDefault()1264 		public boolean isBoldByDefault() {
1265 			return true;
1266 		}
1267 
1268 		/*
1269 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
1270 		 */
1271 		@Override
isItalicByDefault()1272 		public boolean isItalicByDefault() {
1273 			return false;
1274 		}
1275 
1276 		/*
1277 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
1278 		 */
1279 		@Override
isEnabledByDefault()1280 		public boolean isEnabledByDefault() {
1281 			return false;
1282 		}
1283 
1284 		/*
1285 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
1286 		 */
1287 		@Override
getDisplayName()1288 		public String getDisplayName() {
1289 			return JavaEditorMessages.SemanticHighlighting_typeVariables;
1290 		}
1291 
1292 		/*
1293 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
1294 		 */
1295 		@Override
consumes(SemanticToken token)1296 		public boolean consumes(SemanticToken token) {
1297 
1298 			// 1: match types in type parameter lists
1299 			SimpleName name= token.getNode();
1300 			ASTNode node= name.getParent();
1301 			if (node.getNodeType() != ASTNode.SIMPLE_TYPE && node.getNodeType() != ASTNode.TYPE_PARAMETER)
1302 				return false;
1303 
1304 			// 2: match generic type variable references
1305 			IBinding binding= token.getBinding();
1306 			return binding instanceof ITypeBinding && ((ITypeBinding) binding).isTypeVariable();
1307 		}
1308 	}
1309 
1310 	/**
1311 	 * Semantic highlighting for classes.
1312 	 * @since 3.2
1313 	 */
1314 	private static final class ClassHighlighting extends SemanticHighlighting {
1315 
1316 		/*
1317 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
1318 		 */
1319 		@Override
getPreferenceKey()1320 		public String getPreferenceKey() {
1321 			return CLASS;
1322 		}
1323 
1324 		/*
1325 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
1326 		 */
1327 		@Override
getDefaultDefaultTextColor()1328 		public RGB getDefaultDefaultTextColor() {
1329 			return new RGB(0, 80, 50);
1330 		}
1331 
1332 		/*
1333 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
1334 		 */
1335 		@Override
isBoldByDefault()1336 		public boolean isBoldByDefault() {
1337 			return false;
1338 		}
1339 
1340 		/*
1341 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
1342 		 */
1343 		@Override
isItalicByDefault()1344 		public boolean isItalicByDefault() {
1345 			return false;
1346 		}
1347 
1348 		/*
1349 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
1350 		 */
1351 		@Override
isEnabledByDefault()1352 		public boolean isEnabledByDefault() {
1353 			return false;
1354 		}
1355 
1356 		/*
1357 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
1358 		 */
1359 		@Override
getDisplayName()1360 		public String getDisplayName() {
1361 			return JavaEditorMessages.SemanticHighlighting_classes;
1362 		}
1363 
1364 		/*
1365 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
1366 		 */
1367 		@Override
consumes(SemanticToken token)1368 		public boolean consumes(SemanticToken token) {
1369 
1370 			// 1: match types
1371 			SimpleName name= token.getNode();
1372 			ASTNode node= name.getParent();
1373 			int nodeType= node.getNodeType();
1374 			if (nodeType != ASTNode.SIMPLE_TYPE && nodeType != ASTNode.THIS_EXPRESSION && nodeType != ASTNode.QUALIFIED_TYPE  && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.TYPE_DECLARATION && nodeType != ASTNode.METHOD_INVOCATION)
1375 				return false;
1376 			while (nodeType == ASTNode.QUALIFIED_NAME) {
1377 				node= node.getParent();
1378 				nodeType= node.getNodeType();
1379 				if (nodeType == ASTNode.IMPORT_DECLARATION)
1380 					return false;
1381 			}
1382 
1383 			// 2: match classes
1384 			IBinding binding= token.getBinding();
1385 			return binding instanceof ITypeBinding && ((ITypeBinding) binding).isClass();
1386 		}
1387 	}
1388 
1389 	/**
1390 	 * Semantic highlighting for enums.
1391 	 * @since 3.2
1392 	 */
1393 	private static final class EnumHighlighting extends SemanticHighlighting {
1394 
1395 		/*
1396 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
1397 		 */
1398 		@Override
getPreferenceKey()1399 		public String getPreferenceKey() {
1400 			return ENUM;
1401 		}
1402 
1403 		/*
1404 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
1405 		 */
1406 		@Override
getDefaultDefaultTextColor()1407 		public RGB getDefaultDefaultTextColor() {
1408 			return new RGB(100, 70, 50);
1409 		}
1410 
1411 		/*
1412 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
1413 		 */
1414 		@Override
isBoldByDefault()1415 		public boolean isBoldByDefault() {
1416 			return false;
1417 		}
1418 
1419 		/*
1420 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
1421 		 */
1422 		@Override
isItalicByDefault()1423 		public boolean isItalicByDefault() {
1424 			return false;
1425 		}
1426 
1427 		/*
1428 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
1429 		 */
1430 		@Override
isEnabledByDefault()1431 		public boolean isEnabledByDefault() {
1432 			return false;
1433 		}
1434 
1435 		/*
1436 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
1437 		 */
1438 		@Override
getDisplayName()1439 		public String getDisplayName() {
1440 			return JavaEditorMessages.SemanticHighlighting_enums;
1441 		}
1442 
1443 		/*
1444 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
1445 		 */
1446 		@Override
consumes(SemanticToken token)1447 		public boolean consumes(SemanticToken token) {
1448 
1449 			// 1: match types
1450 			SimpleName name= token.getNode();
1451 			ASTNode node= name.getParent();
1452 			int nodeType= node.getNodeType();
1453 			if (nodeType != ASTNode.METHOD_INVOCATION && nodeType != ASTNode.SIMPLE_TYPE && nodeType != ASTNode.QUALIFIED_TYPE && nodeType != ASTNode.QUALIFIED_NAME
1454 					&& nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.ENUM_DECLARATION)
1455 				return false;
1456 			while (nodeType == ASTNode.QUALIFIED_NAME) {
1457 				node= node.getParent();
1458 				nodeType= node.getNodeType();
1459 				if (nodeType == ASTNode.IMPORT_DECLARATION)
1460 					return false;
1461 			}
1462 
1463 			// 2: match enums
1464 			IBinding binding= token.getBinding();
1465 			return binding instanceof ITypeBinding && ((ITypeBinding) binding).isEnum();
1466 		}
1467 	}
1468 
1469 	/**
1470 	 * Semantic highlighting for interfaces.
1471 	 * @since 3.2
1472 	 */
1473 	private static final class InterfaceHighlighting extends SemanticHighlighting {
1474 
1475 		/*
1476 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
1477 		 */
1478 		@Override
getPreferenceKey()1479 		public String getPreferenceKey() {
1480 			return INTERFACE;
1481 		}
1482 
1483 		/*
1484 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
1485 		 */
1486 		@Override
getDefaultDefaultTextColor()1487 		public RGB getDefaultDefaultTextColor() {
1488 			return new RGB(50, 63, 112);
1489 		}
1490 
1491 		/*
1492 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
1493 		 */
1494 		@Override
isBoldByDefault()1495 		public boolean isBoldByDefault() {
1496 			return false;
1497 		}
1498 
1499 		/*
1500 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
1501 		 */
1502 		@Override
isItalicByDefault()1503 		public boolean isItalicByDefault() {
1504 			return false;
1505 		}
1506 
1507 		/*
1508 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
1509 		 */
1510 		@Override
isEnabledByDefault()1511 		public boolean isEnabledByDefault() {
1512 			return false;
1513 		}
1514 
1515 		/*
1516 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
1517 		 */
1518 		@Override
getDisplayName()1519 		public String getDisplayName() {
1520 			return JavaEditorMessages.SemanticHighlighting_interfaces;
1521 		}
1522 
1523 		/*
1524 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
1525 		 */
1526 		@Override
consumes(SemanticToken token)1527 		public boolean consumes(SemanticToken token) {
1528 
1529 			// 1: match types
1530 			SimpleName name= token.getNode();
1531 			ASTNode node= name.getParent();
1532 			int nodeType= node.getNodeType();
1533 			if (nodeType != ASTNode.SIMPLE_TYPE && nodeType != ASTNode.QUALIFIED_TYPE  && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.TYPE_DECLARATION)
1534 				return false;
1535 			while (nodeType == ASTNode.QUALIFIED_NAME) {
1536 				node= node.getParent();
1537 				nodeType= node.getNodeType();
1538 				if (nodeType == ASTNode.IMPORT_DECLARATION)
1539 					return false;
1540 			}
1541 
1542 			// 2: match interfaces
1543 			IBinding binding= token.getBinding();
1544 			return binding instanceof ITypeBinding && ((ITypeBinding) binding).isInterface();
1545 		}
1546 	}
1547 
1548 	/**
1549 	 * Semantic highlighting for annotation types.
1550 	 * @since 3.2
1551 	 */
1552 	private static final class AnnotationHighlighting extends SemanticHighlighting {
1553 
1554 		/*
1555 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
1556 		 */
1557 		@Override
getPreferenceKey()1558 		public String getPreferenceKey() {
1559 			return ANNOTATION;
1560 		}
1561 
1562 		/*
1563 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
1564 		 */
1565 		@Override
getDefaultDefaultTextColor()1566 		public RGB getDefaultDefaultTextColor() {
1567 			return new RGB(100, 100, 100);
1568 		}
1569 
1570 		/*
1571 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
1572 		 */
1573 		@Override
isBoldByDefault()1574 		public boolean isBoldByDefault() {
1575 			return false;
1576 		}
1577 
1578 		/*
1579 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
1580 		 */
1581 		@Override
isItalicByDefault()1582 		public boolean isItalicByDefault() {
1583 			return false;
1584 		}
1585 
1586 		/*
1587 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
1588 		 */
1589 		@Override
isEnabledByDefault()1590 		public boolean isEnabledByDefault() {
1591 			return true; // as it replaces the syntax based highlighting which is always enabled
1592 		}
1593 
1594 		/*
1595 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
1596 		 */
1597 		@Override
getDisplayName()1598 		public String getDisplayName() {
1599 			return JavaEditorMessages.SemanticHighlighting_annotations;
1600 		}
1601 
1602 		/*
1603 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
1604 		 */
1605 		@Override
consumes(SemanticToken token)1606 		public boolean consumes(SemanticToken token) {
1607 
1608 			// 1: match types
1609 			SimpleName name= token.getNode();
1610 			ASTNode node= name.getParent();
1611 			int nodeType= node.getNodeType();
1612 			if (nodeType != ASTNode.SIMPLE_TYPE && nodeType != ASTNode.QUALIFIED_TYPE  && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.ANNOTATION_TYPE_DECLARATION
1613 					&& nodeType != ASTNode.MARKER_ANNOTATION && nodeType != ASTNode.NORMAL_ANNOTATION && nodeType != ASTNode.SINGLE_MEMBER_ANNOTATION)
1614 				return false;
1615 			while (nodeType == ASTNode.QUALIFIED_NAME) {
1616 				node= node.getParent();
1617 				nodeType= node.getNodeType();
1618 				if (nodeType == ASTNode.IMPORT_DECLARATION)
1619 					return false;
1620 			}
1621 
1622 			// 2: match annotations
1623 			IBinding binding= token.getBinding();
1624 			return binding instanceof ITypeBinding && ((ITypeBinding) binding).isAnnotation();
1625 		}
1626 	}
1627 
1628 	/**
1629 	 * Semantic highlighting for annotation types.
1630 	 * @since 3.2
1631 	 */
1632 	private static final class TypeArgumentHighlighting extends SemanticHighlighting {
1633 
1634 		/*
1635 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
1636 		 */
1637 		@Override
getPreferenceKey()1638 		public String getPreferenceKey() {
1639 			return TYPE_ARGUMENT;
1640 		}
1641 
1642 		/*
1643 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
1644 		 */
1645 		@Override
getDefaultDefaultTextColor()1646 		public RGB getDefaultDefaultTextColor() {
1647 			return new RGB(13, 100, 0);
1648 		}
1649 
1650 		/*
1651 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
1652 		 */
1653 		@Override
isBoldByDefault()1654 		public boolean isBoldByDefault() {
1655 			return false;
1656 		}
1657 
1658 		/*
1659 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
1660 		 */
1661 		@Override
isItalicByDefault()1662 		public boolean isItalicByDefault() {
1663 			return false;
1664 		}
1665 
1666 		/*
1667 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
1668 		 */
1669 		@Override
isEnabledByDefault()1670 		public boolean isEnabledByDefault() {
1671 			return false;
1672 		}
1673 
1674 		/*
1675 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
1676 		 */
1677 		@Override
getDisplayName()1678 		public String getDisplayName() {
1679 			return JavaEditorMessages.SemanticHighlighting_typeArguments;
1680 		}
1681 
1682 		/*
1683 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
1684 		 */
1685 		@Override
consumes(SemanticToken token)1686 		public boolean consumes(SemanticToken token) {
1687 
1688 			// 1: match types
1689 			SimpleName name= token.getNode();
1690 			ASTNode node= name.getParent();
1691 			int nodeType= node.getNodeType();
1692 			if (nodeType != ASTNode.SIMPLE_TYPE && nodeType != ASTNode.QUALIFIED_TYPE)
1693 				return false;
1694 
1695 			// 2: match type arguments
1696 			StructuralPropertyDescriptor locationInParent= node.getLocationInParent();
1697 			if (locationInParent == ParameterizedType.TYPE_ARGUMENTS_PROPERTY)
1698 				return true;
1699 
1700 			return false;
1701 		}
1702 	}
1703 
1704 	/**
1705 	 * Semantic highlighting for numbers.
1706 	 * @since 3.4
1707 	 */
1708 	private static final class NumberHighlighting extends SemanticHighlighting {
1709 
1710 		/*
1711 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
1712 		 */
1713 		@Override
getPreferenceKey()1714 		public String getPreferenceKey() {
1715 			return NUMBER;
1716 		}
1717 
1718 		/*
1719 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
1720 		 */
1721 		@Override
getDefaultDefaultTextColor()1722 		public RGB getDefaultDefaultTextColor() {
1723 			return new RGB(42, 0, 255);
1724 		}
1725 
1726 		/*
1727 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
1728 		 */
1729 		@Override
isBoldByDefault()1730 		public boolean isBoldByDefault() {
1731 			return false;
1732 		}
1733 
1734 		/*
1735 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
1736 		 */
1737 		@Override
isItalicByDefault()1738 		public boolean isItalicByDefault() {
1739 			return false;
1740 		}
1741 
1742 		/*
1743 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
1744 		 */
1745 		@Override
isEnabledByDefault()1746 		public boolean isEnabledByDefault() {
1747 			return false;
1748 		}
1749 
1750 		/*
1751 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
1752 		 */
1753 		@Override
getDisplayName()1754 		public String getDisplayName() {
1755 			return JavaEditorMessages.SemanticHighlighting_numbers;
1756 		}
1757 
1758 		/*
1759 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
1760 		 */
1761 		@Override
consumes(SemanticToken token)1762 		public boolean consumes(SemanticToken token) {
1763 			return false;
1764 		}
1765 
1766 		/*
1767 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumesLiteral(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
1768 		 */
1769 		@Override
consumesLiteral(SemanticToken token)1770 		public boolean consumesLiteral(SemanticToken token) {
1771 			Expression expr= token.getLiteral();
1772 			return expr != null && expr.getNodeType() == ASTNode.NUMBER_LITERAL;
1773 		}
1774 	}
1775 
1776 	/**
1777 	 * Semantic highlighting for classes.
1778 	 * @since 3.7
1779 	 */
1780 	private static final class AbstractClassHighlighting extends SemanticHighlighting {
1781 
1782 		/*
1783 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
1784 		 */
1785 		@Override
getPreferenceKey()1786 		public String getPreferenceKey() {
1787 			return ABSTRACT_CLASS;
1788 		}
1789 
1790 		/*
1791 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
1792 		 */
1793 		@Override
getDefaultDefaultTextColor()1794 		public RGB getDefaultDefaultTextColor() {
1795 			return new RGB(139, 136, 22);
1796 		}
1797 
1798 		/*
1799 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
1800 		 */
1801 		@Override
isBoldByDefault()1802 		public boolean isBoldByDefault() {
1803 			return false;
1804 		}
1805 
1806 		/*
1807 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
1808 		 */
1809 		@Override
isItalicByDefault()1810 		public boolean isItalicByDefault() {
1811 			return false;
1812 		}
1813 
1814 		/*
1815 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
1816 		 */
1817 		@Override
isEnabledByDefault()1818 		public boolean isEnabledByDefault() {
1819 			return false;
1820 		}
1821 
1822 		/*
1823 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
1824 		 */
1825 		@Override
getDisplayName()1826 		public String getDisplayName() {
1827 			return JavaEditorMessages.SemanticHighlighting_abstractClasses;
1828 		}
1829 
1830 		/*
1831 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
1832 		 */
1833 		@Override
consumes(SemanticToken token)1834 		public boolean consumes(SemanticToken token) {
1835 
1836 			// 1: match types
1837 			SimpleName name= token.getNode();
1838 			ASTNode node= name.getParent();
1839 			int nodeType= node.getNodeType();
1840 			if (nodeType != ASTNode.SIMPLE_TYPE && nodeType != ASTNode.THIS_EXPRESSION && nodeType != ASTNode.QUALIFIED_TYPE  && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.TYPE_DECLARATION && nodeType != ASTNode.METHOD_INVOCATION)
1841 				return false;
1842 			while (nodeType == ASTNode.QUALIFIED_NAME) {
1843 				node= node.getParent();
1844 				nodeType= node.getNodeType();
1845 				if (nodeType == ASTNode.IMPORT_DECLARATION)
1846 					return false;
1847 			}
1848 
1849 			// 2: match classes
1850 			IBinding binding= token.getBinding();
1851 			if (binding instanceof ITypeBinding) {
1852 				ITypeBinding typeBinding= (ITypeBinding) binding;
1853 				// see also ClassHighlighting
1854 				return typeBinding.isClass() && (typeBinding.getModifiers() & Modifier.ABSTRACT) != 0;
1855 			}
1856 
1857 			return false;
1858 		}
1859 	}
1860 
1861 	/**
1862 	 * Semantic highlighting for inherited field access.
1863 	 * @since 3.8
1864 	 */
1865 	private static final class InheritedFieldHighlighting extends SemanticHighlighting {
1866 
1867 		/*
1868 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
1869 		 */
1870 		@Override
getPreferenceKey()1871 		public String getPreferenceKey() {
1872 			return INHERITED_FIELD;
1873 		}
1874 
1875 		/*
1876 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
1877 		 */
1878 		@Override
getDefaultDefaultTextColor()1879 		public RGB getDefaultDefaultTextColor() {
1880 			return new RGB(0, 0, 192);
1881 		}
1882 
1883 		/*
1884 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
1885 		 */
1886 		@Override
isBoldByDefault()1887 		public boolean isBoldByDefault() {
1888 			return false;
1889 		}
1890 
1891 		/*
1892 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
1893 		 */
1894 		@Override
isItalicByDefault()1895 		public boolean isItalicByDefault() {
1896 			return false;
1897 		}
1898 
1899 		/*
1900 		 * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
1901 		 */
1902 		@Override
isEnabledByDefault()1903 		public boolean isEnabledByDefault() {
1904 			return false;
1905 		}
1906 
1907 		/*
1908 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
1909 		 */
1910 		@Override
getDisplayName()1911 		public String getDisplayName() {
1912 			return JavaEditorMessages.SemanticHighlighting_inheritedField;
1913 		}
1914 
1915 		/*
1916 		 * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#isMatched(org.eclipse.jdt.core.dom.ASTNode)
1917 		 */
1918 		@Override
consumes(final SemanticToken token)1919 		public boolean consumes(final SemanticToken token) {
1920 			final SimpleName node= token.getNode();
1921 			if (node.isDeclaration()) {
1922 				return false;
1923 			}
1924 
1925 			final IBinding binding= token.getBinding();
1926 			if (binding == null || binding.getKind() != IBinding.VARIABLE) {
1927 				return false;
1928 			}
1929 
1930 			ITypeBinding currentType= Bindings.getBindingOfParentType(node);
1931 			ITypeBinding declaringType= ((IVariableBinding) binding).getDeclaringClass();
1932 			if (declaringType == null || currentType == declaringType)
1933 				return false;
1934 
1935 			return Bindings.isSuperType(declaringType, currentType);
1936 		}
1937 	}
1938 
1939 	/**
1940 	 * Semantic highlighting for 'var' keyword.
1941 	 */
1942 	static final class VarKeywordHighlighting extends SemanticHighlighting {
1943 
1944 		@Override
getPreferenceKey()1945 		public String getPreferenceKey() {
1946 			return VAR_KEYWORD;
1947 		}
1948 
1949 		@Override
getDefaultDefaultTextColor()1950 		public RGB getDefaultDefaultTextColor() {
1951 			return new RGB(127, 0, 85);
1952 		}
1953 
1954 		@Override
isBoldByDefault()1955 		public boolean isBoldByDefault() {
1956 			return true;
1957 		}
1958 
1959 		@Override
isItalicByDefault()1960 		public boolean isItalicByDefault() {
1961 			return false;
1962 		}
1963 
1964 		@Override
isEnabledByDefault()1965 		public boolean isEnabledByDefault() {
1966 			return true;
1967 		}
1968 
1969 		@Override
getDisplayName()1970 		public String getDisplayName() {
1971 			return PreferencesMessages.JavaEditorPreferencePage_varKeyword;
1972 		}
1973 
1974 		@Override
consumes(SemanticToken token)1975 		public boolean consumes(SemanticToken token) {
1976 			return false;
1977 		}
1978 	}
1979 
1980 	/**
1981 	 * Semantic highlighting for 'record' keyword.
1982 	 */
1983 	static final class RecordKeywordHighlighting extends SemanticHighlighting {
1984 
1985 		@Override
getPreferenceKey()1986 		public String getPreferenceKey() {
1987 			return RECORD_KEYWORD;
1988 		}
1989 
1990 		@Override
getDefaultDefaultTextColor()1991 		public RGB getDefaultDefaultTextColor() {
1992 			return new RGB(127, 0, 85);
1993 		}
1994 
1995 		@Override
isBoldByDefault()1996 		public boolean isBoldByDefault() {
1997 			return true;
1998 		}
1999 
2000 		@Override
isItalicByDefault()2001 		public boolean isItalicByDefault() {
2002 			return false;
2003 		}
2004 
2005 		@Override
isEnabledByDefault()2006 		public boolean isEnabledByDefault() {
2007 			return true;
2008 		}
2009 
2010 		@Override
getDisplayName()2011 		public String getDisplayName() {
2012 			return PreferencesMessages.JavaEditorPreferencePage_recordKeyword;
2013 		}
2014 
2015 		@Override
consumes(SemanticToken token)2016 		public boolean consumes(SemanticToken token) {
2017 			return false;
2018 		}
2019 	}
2020 
2021 	/**
2022 	 * Semantic highlighting for 'yield' keyword.
2023 	 */
2024 	static final class YieldKeywordHighlighting extends SemanticHighlighting {
2025 
2026 		@Override
getPreferenceKey()2027 		public String getPreferenceKey() {
2028 			return YIELD_KEYWORD;
2029 		}
2030 
2031 		@Override
getDefaultDefaultTextColor()2032 		public RGB getDefaultDefaultTextColor() {
2033 			return new RGB(127, 0, 85);
2034 		}
2035 
2036 		@Override
isBoldByDefault()2037 		public boolean isBoldByDefault() {
2038 			return true;
2039 		}
2040 
2041 		@Override
isItalicByDefault()2042 		public boolean isItalicByDefault() {
2043 			return false;
2044 		}
2045 
2046 		@Override
isEnabledByDefault()2047 		public boolean isEnabledByDefault() {
2048 			return true;
2049 		}
2050 
2051 		@Override
getDisplayName()2052 		public String getDisplayName() {
2053 			return PreferencesMessages.JavaEditorPreferencePage_yieldKeyword;
2054 		}
2055 
2056 		@Override
consumes(SemanticToken token)2057 		public boolean consumes(SemanticToken token) {
2058 			return false;
2059 		}
2060 	}
2061 
2062 	/**
2063 	 * A named preference that controls the given semantic highlighting's color.
2064 	 *
2065 	 * @param semanticHighlighting the semantic highlighting
2066 	 * @return the color preference key
2067 	 */
getColorPreferenceKey(SemanticHighlighting semanticHighlighting)2068 	public static String getColorPreferenceKey(SemanticHighlighting semanticHighlighting) {
2069 		return PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + semanticHighlighting.getPreferenceKey() + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_COLOR_SUFFIX;
2070 	}
2071 
2072 	/**
2073 	 * A named preference that controls if the given semantic highlighting has the text attribute bold.
2074 	 *
2075 	 * @param semanticHighlighting the semantic highlighting
2076 	 * @return the bold preference key
2077 	 */
getBoldPreferenceKey(SemanticHighlighting semanticHighlighting)2078 	public static String getBoldPreferenceKey(SemanticHighlighting semanticHighlighting) {
2079 		return PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + semanticHighlighting.getPreferenceKey() + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_BOLD_SUFFIX;
2080 	}
2081 
2082 	/**
2083 	 * A named preference that controls if the given semantic highlighting has the text attribute italic.
2084 	 *
2085 	 * @param semanticHighlighting the semantic highlighting
2086 	 * @return the italic preference key
2087 	 */
getItalicPreferenceKey(SemanticHighlighting semanticHighlighting)2088 	public static String getItalicPreferenceKey(SemanticHighlighting semanticHighlighting) {
2089 		return PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + semanticHighlighting.getPreferenceKey() + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_ITALIC_SUFFIX;
2090 	}
2091 
2092 	/**
2093 	 * A named preference that controls if the given semantic highlighting has the text attribute strikethrough.
2094 	 *
2095 	 * @param semanticHighlighting the semantic highlighting
2096 	 * @return the strikethrough preference key
2097 	 * @since 3.1
2098 	 */
getStrikethroughPreferenceKey(SemanticHighlighting semanticHighlighting)2099 	public static String getStrikethroughPreferenceKey(SemanticHighlighting semanticHighlighting) {
2100 		return PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + semanticHighlighting.getPreferenceKey() + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_STRIKETHROUGH_SUFFIX;
2101 	}
2102 
2103 	/**
2104 	 * A named preference that controls if the given semantic highlighting has the text attribute underline.
2105 	 *
2106 	 * @param semanticHighlighting the semantic highlighting
2107 	 * @return the underline preference key
2108 	 * @since 3.1
2109 	 */
getUnderlinePreferenceKey(SemanticHighlighting semanticHighlighting)2110 	public static String getUnderlinePreferenceKey(SemanticHighlighting semanticHighlighting) {
2111 		return PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + semanticHighlighting.getPreferenceKey() + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_UNDERLINE_SUFFIX;
2112 	}
2113 
2114 	/**
2115 	 * A named preference that controls if the given semantic highlighting is enabled.
2116 	 *
2117 	 * @param semanticHighlighting the semantic highlighting
2118 	 * @return the enabled preference key
2119 	 */
getEnabledPreferenceKey(SemanticHighlighting semanticHighlighting)2120 	public static String getEnabledPreferenceKey(SemanticHighlighting semanticHighlighting) {
2121 		return PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + semanticHighlighting.getPreferenceKey() + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_ENABLED_SUFFIX;
2122 	}
2123 
2124 	/**
2125 	 * @return The semantic highlightings, the order defines the precedence of matches, the first match wins.
2126 	 */
getSemanticHighlightings()2127 	public static SemanticHighlighting[] getSemanticHighlightings() {
2128 		if (fgSemanticHighlightings == null)
2129 			fgSemanticHighlightings= new SemanticHighlighting[] {
2130 				new DeprecatedMemberHighlighting(),
2131 				new AutoboxHighlighting(),
2132 				new StaticFinalFieldHighlighting(),
2133 				new StaticFieldHighlighting(),
2134 				new InheritedFieldHighlighting(),
2135 				new FieldHighlighting(),
2136 				new MethodDeclarationHighlighting(),
2137 				new StaticMethodInvocationHighlighting(),
2138 				new AbstractMethodInvocationHighlighting(),
2139 				new AnnotationElementReferenceHighlighting(),
2140 				new InheritedMethodInvocationHighlighting(),
2141 				new ParameterVariableHighlighting(),
2142 				new LocalVariableDeclarationHighlighting(),
2143 				new LocalVariableHighlighting(),
2144 				new TypeVariableHighlighting(), // before type arguments!
2145 				new MethodHighlighting(), // before types to get ctors
2146 				new TypeArgumentHighlighting(), // before other types
2147 				new AbstractClassHighlighting(), // before classes
2148 				new ClassHighlighting(),
2149 				new EnumHighlighting(),
2150 				new AnnotationHighlighting(), // before interfaces
2151 				new InterfaceHighlighting(),
2152 				new NumberHighlighting(),
2153 				new VarKeywordHighlighting(),
2154 				new YieldKeywordHighlighting(),
2155 				new RecordKeywordHighlighting()
2156 			};
2157 		return fgSemanticHighlightings;
2158 	}
2159 
2160 	/**
2161 	 * Initialize default preferences in the given preference store.
2162 	 * @param store The preference store
2163 	 */
initDefaults(IPreferenceStore store)2164 	public static void initDefaults(IPreferenceStore store) {
2165 		SemanticHighlighting[] semanticHighlightings= getSemanticHighlightings();
2166 		for (SemanticHighlighting semanticHighlighting : semanticHighlightings) {
2167 			setDefaultAndFireEvent(store, SemanticHighlightings.getColorPreferenceKey(semanticHighlighting), semanticHighlighting.getDefaultTextColor());
2168 			store.setDefault(SemanticHighlightings.getBoldPreferenceKey(semanticHighlighting), semanticHighlighting.isBoldByDefault());
2169 			store.setDefault(SemanticHighlightings.getItalicPreferenceKey(semanticHighlighting), semanticHighlighting.isItalicByDefault());
2170 			store.setDefault(SemanticHighlightings.getStrikethroughPreferenceKey(semanticHighlighting), semanticHighlighting.isStrikethroughByDefault());
2171 			store.setDefault(SemanticHighlightings.getUnderlinePreferenceKey(semanticHighlighting), semanticHighlighting.isUnderlineByDefault());
2172 			store.setDefault(SemanticHighlightings.getEnabledPreferenceKey(semanticHighlighting), semanticHighlighting.isEnabledByDefault());
2173 		}
2174 
2175 		convertMethodHighlightingPreferences(store);
2176 		convertAnnotationHighlightingPreferences(store);
2177 	}
2178 
2179 	/**
2180 	 * Tests whether <code>event</code> in <code>store</code> affects the
2181 	 * enablement of semantic highlighting.
2182 	 *
2183 	 * @param store the preference store where <code>event</code> was observed
2184 	 * @param event the property change under examination
2185 	 * @return <code>true</code> if <code>event</code> changed semantic
2186 	 *         highlighting enablement, <code>false</code> if it did not
2187 	 * @since 3.1
2188 	 */
affectsEnablement(IPreferenceStore store, PropertyChangeEvent event)2189 	public static boolean affectsEnablement(IPreferenceStore store, PropertyChangeEvent event) {
2190 		String relevantKey= null;
2191 		SemanticHighlighting[] highlightings= getSemanticHighlightings();
2192 		for (SemanticHighlighting highlighting : highlightings) {
2193 			if (event.getProperty().equals(getEnabledPreferenceKey(highlighting))) {
2194 				relevantKey= event.getProperty();
2195 				break;
2196 			}
2197 		}
2198 		if (relevantKey == null)
2199 			return false;
2200 
2201 		for (SemanticHighlighting highlighting : highlightings) {
2202 			String key= getEnabledPreferenceKey(highlighting);
2203 			if (key.equals(relevantKey))
2204 				continue;
2205 			if (store.getBoolean(key))
2206 				return false; // another is still enabled or was enabled before
2207 		}
2208 
2209 		// all others are disabled, so toggling relevantKey affects the enablement
2210 		return true;
2211 	}
2212 
2213 	/**
2214 	 * Tests whether semantic highlighting is currently enabled.
2215 	 *
2216 	 * @param store the preference store to consult
2217 	 * @return <code>true</code> if semantic highlighting is enabled,
2218 	 *         <code>false</code> if it is not
2219 	 * @since 3.1
2220 	 */
isEnabled(IPreferenceStore store)2221 	public static boolean isEnabled(IPreferenceStore store) {
2222 		SemanticHighlighting[] highlightings= getSemanticHighlightings();
2223 		boolean enable= false;
2224 		for (SemanticHighlighting highlighting : highlightings) {
2225 			String enabledKey= getEnabledPreferenceKey(highlighting);
2226 			if (store.getBoolean(enabledKey)) {
2227 				enable= true;
2228 				break;
2229 			}
2230 		}
2231 
2232 		return enable;
2233 	}
2234 
2235 	/**
2236 	 * In 3.0, methods were highlighted by a rule-based word matcher that
2237 	 * matched any identifier that was followed by possibly white space and a
2238 	 * left parenthesis.
2239 	 * <p>
2240 	 * With generics, this does not work any longer for constructors of generic
2241 	 * types, and the highlighting has been moved to be a semantic highlighting.
2242 	 * Because different preference key naming schemes are used, we have to
2243 	 * migrate the old settings to the new ones, which is done here. Nothing
2244 	 * needs to be done if the old settings were set to the default values.
2245 	 * </p>
2246 	 *
2247 	 * @param store the preference store to migrate
2248 	 * @since 3.1
2249 	 */
convertMethodHighlightingPreferences(IPreferenceStore store)2250 	private static void convertMethodHighlightingPreferences(IPreferenceStore store) {
2251 		String colorkey= PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + METHOD + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_COLOR_SUFFIX;
2252 		String boldkey= PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + METHOD + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_BOLD_SUFFIX;
2253 		String italickey= PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + METHOD + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_ITALIC_SUFFIX;
2254 		String enabledkey= PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + METHOD + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_ENABLED_SUFFIX;
2255 
2256 		@SuppressWarnings("deprecation") String oldColorkey= PreferenceConstants.EDITOR_JAVA_METHOD_NAME_COLOR;
2257 		@SuppressWarnings("deprecation") String oldBoldkey= PreferenceConstants.EDITOR_JAVA_METHOD_NAME_BOLD;
2258 		@SuppressWarnings("deprecation") String oldItalickey= PreferenceConstants.EDITOR_JAVA_METHOD_NAME_ITALIC;
2259 
2260 		if (conditionalReset(store, oldColorkey, colorkey)
2261 				|| conditionalReset(store, oldBoldkey, boldkey)
2262 				|| conditionalReset(store, oldItalickey, italickey)) {
2263 			store.setValue(enabledkey, true);
2264 		}
2265 
2266 	}
2267 
2268 	/**
2269 	 * In 3.1, annotations were highlighted by a rule-based word matcher that matched any identifier
2270 	 * preceded by an '@' sign and possibly white space.
2271 	 * <p>
2272 	 * This does not work when there is a comment between the '@' and the annotation, results in
2273 	 * stale highlighting if there is a new line between the '@' and the annotation, and does not
2274 	 * work for highlighting annotation declarations. Because different preference key naming
2275 	 * schemes are used, we have to migrate the old settings to the new ones, which is done here.
2276 	 * Nothing needs to be done if the old settings were set to the default values.
2277 	 * </p>
2278 	 *
2279 	 * @param store the preference store to migrate
2280 	 * @since 3.2
2281 	 */
convertAnnotationHighlightingPreferences(IPreferenceStore store)2282 	private static void convertAnnotationHighlightingPreferences(IPreferenceStore store) {
2283 		String colorkey= PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + ANNOTATION + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_COLOR_SUFFIX;
2284 		String boldkey= PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + ANNOTATION + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_BOLD_SUFFIX;
2285 		String italickey= PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + ANNOTATION + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_ITALIC_SUFFIX;
2286 		String strikethroughKey= PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + ANNOTATION + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_STRIKETHROUGH_SUFFIX;
2287 		String underlineKey= PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + ANNOTATION + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_UNDERLINE_SUFFIX;
2288 		String enabledkey= PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + ANNOTATION + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_ENABLED_SUFFIX;
2289 
2290 		@SuppressWarnings("deprecation") String oldColorkey= PreferenceConstants.EDITOR_JAVA_ANNOTATION_COLOR;
2291 		@SuppressWarnings("deprecation") String oldBoldkey= PreferenceConstants.EDITOR_JAVA_ANNOTATION_BOLD;
2292 		@SuppressWarnings("deprecation") String oldItalickey= PreferenceConstants.EDITOR_JAVA_ANNOTATION_ITALIC;
2293 		@SuppressWarnings("deprecation") String oldStrikethroughKey= PreferenceConstants.EDITOR_JAVA_ANNOTATION_STRIKETHROUGH;
2294 		@SuppressWarnings("deprecation") String oldUnderlineKey= PreferenceConstants.EDITOR_JAVA_ANNOTATION_UNDERLINE;
2295 
2296 		if (conditionalReset(store, oldColorkey, colorkey)
2297 				|| conditionalReset(store, oldBoldkey, boldkey)
2298 				|| conditionalReset(store, oldItalickey, italickey)
2299 				|| conditionalReset(store, oldStrikethroughKey, strikethroughKey)
2300 				|| conditionalReset(store, oldUnderlineKey, underlineKey)) {
2301 			store.setValue(enabledkey, true);
2302 		}
2303 
2304 	}
2305 
2306 	/**
2307 	 * If the setting pointed to by <code>oldKey</code> is not the default
2308 	 * setting, store that setting under <code>newKey</code> and reset
2309 	 * <code>oldKey</code> to its default setting.
2310 	 * <p>
2311 	 * Returns <code>true</code> if any changes were made.
2312 	 * </p>
2313 	 *
2314 	 * @param store the preference store to read from and write to
2315 	 * @param oldKey the old preference key
2316 	 * @param newKey the new preference key
2317 	 * @return <code>true</code> if <code>store</code> was modified,
2318 	 *         <code>false</code> if not
2319 	 * @since 3.1
2320 	 */
conditionalReset(IPreferenceStore store, String oldKey, String newKey)2321 	private static boolean conditionalReset(IPreferenceStore store, String oldKey, String newKey) {
2322 		if (!store.isDefault(oldKey)) {
2323 			if (store.isDefault(newKey))
2324 				store.setValue(newKey, store.getString(oldKey));
2325 			store.setToDefault(oldKey);
2326 			return true;
2327 		}
2328 		return false;
2329 	}
2330 
2331 	/**
2332 	 * Sets the default value and fires a property
2333 	 * change event if necessary.
2334 	 *
2335 	 * @param store	the preference store
2336 	 * @param key the preference key
2337 	 * @param newValue the new value
2338 	 * @since 3.3
2339 	 */
setDefaultAndFireEvent(IPreferenceStore store, String key, RGB newValue)2340 	private static void setDefaultAndFireEvent(IPreferenceStore store, String key, RGB newValue) {
2341 		RGB oldValue= null;
2342 		if (store.isDefault(key))
2343 			oldValue= PreferenceConverter.getDefaultColor(store, key);
2344 
2345 		PreferenceConverter.setDefault(store, key, newValue);
2346 
2347 		if (oldValue != null && !oldValue.equals(newValue))
2348 			store.firePropertyChangeEvent(key, oldValue, newValue);
2349 	}
2350 
2351 	/**
2352 	 * Extracts the binding from the token's simple name.
2353 	 * Works around bug 62605 to return the correct constructor binding in a ClassInstanceCreation.
2354 	 *
2355 	 * @param token the token to extract the binding from
2356 	 * @return the token's binding, or <code>null</code>
2357 	 */
getBinding(SemanticToken token)2358 	private static IBinding getBinding(SemanticToken token) {
2359 		ASTNode node= token.getNode();
2360 		ASTNode normalized= ASTNodes.getNormalizedNode(node);
2361 		if (normalized.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY) {
2362 			// work around: https://bugs.eclipse.org/bugs/show_bug.cgi?id=62605
2363 			return ((ClassInstanceCreation) normalized.getParent()).resolveConstructorBinding();
2364 		}
2365 		return token.getBinding();
2366 	}
2367 
2368 	/**
2369 	 * Do not instantiate
2370 	 */
SemanticHighlightings()2371 	private SemanticHighlightings() {
2372 	}
2373 }
2374