KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > javaeditor > SemanticHighlightings


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.internal.ui.javaeditor;
13
14 import org.eclipse.swt.graphics.RGB;
15
16 import org.eclipse.jface.preference.IPreferenceStore;
17 import org.eclipse.jface.preference.PreferenceConverter;
18 import org.eclipse.jface.util.PropertyChangeEvent;
19
20 import org.eclipse.jdt.core.dom.ASTNode;
21 import org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration;
22 import org.eclipse.jdt.core.dom.ArrayAccess;
23 import org.eclipse.jdt.core.dom.CastExpression;
24 import org.eclipse.jdt.core.dom.ClassInstanceCreation;
25 import org.eclipse.jdt.core.dom.ConditionalExpression;
26 import org.eclipse.jdt.core.dom.Expression;
27 import org.eclipse.jdt.core.dom.FieldDeclaration;
28 import org.eclipse.jdt.core.dom.IBinding;
29 import org.eclipse.jdt.core.dom.IMethodBinding;
30 import org.eclipse.jdt.core.dom.ITypeBinding;
31 import org.eclipse.jdt.core.dom.IVariableBinding;
32 import org.eclipse.jdt.core.dom.InfixExpression;
33 import org.eclipse.jdt.core.dom.MemberValuePair;
34 import org.eclipse.jdt.core.dom.MethodDeclaration;
35 import org.eclipse.jdt.core.dom.Modifier;
36 import org.eclipse.jdt.core.dom.ParameterizedType;
37 import org.eclipse.jdt.core.dom.PrefixExpression;
38 import org.eclipse.jdt.core.dom.QualifiedName;
39 import org.eclipse.jdt.core.dom.QualifiedType;
40 import org.eclipse.jdt.core.dom.SimpleName;
41 import org.eclipse.jdt.core.dom.SimpleType;
42 import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
43 import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor;
44 import org.eclipse.jdt.core.dom.Type;
45 import org.eclipse.jdt.core.dom.VariableDeclaration;
46 import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
47
48 import org.eclipse.jdt.internal.corext.dom.Bindings;
49
50 import org.eclipse.jdt.ui.PreferenceConstants;
51
52
53 /**
54  * Semantic highlightings
55  *
56  * @since 3.0
57  */

58 public class SemanticHighlightings {
59
60     /**
61      * A named preference part that controls the highlighting of static final fields.
62      */

63     public static final String JavaDoc STATIC_FINAL_FIELD="staticFinalField"; //$NON-NLS-1$
64

65     /**
66      * A named preference part that controls the highlighting of static fields.
67      */

68     public static final String JavaDoc STATIC_FIELD="staticField"; //$NON-NLS-1$
69

70     /**
71      * A named preference part that controls the highlighting of fields.
72      */

73     public static final String JavaDoc FIELD="field"; //$NON-NLS-1$
74

75     /**
76      * A named preference part that controls the highlighting of method declarations.
77      */

78     public static final String JavaDoc METHOD_DECLARATION="methodDeclarationName"; //$NON-NLS-1$
79

80     /**
81      * A named preference part that controls the highlighting of static method invocations.
82      */

83     public static final String JavaDoc STATIC_METHOD_INVOCATION="staticMethodInvocation"; //$NON-NLS-1$
84

85     /**
86      * A named preference part that controls the highlighting of inherited method invocations.
87      */

88     public static final String JavaDoc INHERITED_METHOD_INVOCATION="inheritedMethodInvocation"; //$NON-NLS-1$
89

90     /**
91      * A named preference part that controls the highlighting of annotation element references.
92      * @since 3.1
93      */

94     public static final String JavaDoc ANNOTATION_ELEMENT_REFERENCE="annotationElementReference"; //$NON-NLS-1$
95

96     /**
97      * A named preference part that controls the highlighting of abstract method invocations.
98      */

99     public static final String JavaDoc ABSTRACT_METHOD_INVOCATION="abstractMethodInvocation"; //$NON-NLS-1$
100

101     /**
102      * A named preference part that controls the highlighting of local variables.
103      */

104     public static final String JavaDoc LOCAL_VARIABLE_DECLARATION="localVariableDeclaration"; //$NON-NLS-1$
105

106     /**
107      * A named preference part that controls the highlighting of local variables.
108      */

109     public static final String JavaDoc LOCAL_VARIABLE="localVariable"; //$NON-NLS-1$
110

111     /**
112      * A named preference part that controls the highlighting of parameter variables.
113      */

114     public static final String JavaDoc PARAMETER_VARIABLE="parameterVariable"; //$NON-NLS-1$
115

116     /**
117      * A named preference part that controls the highlighting of deprecated members.
118      */

119     public static final String JavaDoc DEPRECATED_MEMBER="deprecatedMember"; //$NON-NLS-1$
120

121     /**
122      * A named preference part that controls the highlighting of type parameters.
123      * @since 3.1
124      */

125     public static final String JavaDoc TYPE_VARIABLE="typeParameter"; //$NON-NLS-1$
126

127     /**
128      * A named preference part that controls the highlighting of methods
129      * (invocations and declarations).
130      *
131      * @since 3.1
132      */

133     public static final String JavaDoc METHOD="method"; //$NON-NLS-1$
134

135     /**
136      * A named preference part that controls the highlighting of auto(un)boxed
137      * expressions.
138      *
139      * @since 3.1
140      */

141     public static final String JavaDoc AUTOBOXING="autoboxing"; //$NON-NLS-1$
142

143     /**
144      * A named preference part that controls the highlighting of classes.
145      *
146      * @since 3.2
147      */

148     public static final String JavaDoc CLASS="class"; //$NON-NLS-1$
149

150     /**
151      * A named preference part that controls the highlighting of enums.
152      *
153      * @since 3.2
154      */

155     public static final String JavaDoc ENUM="enum"; //$NON-NLS-1$
156

157     /**
158      * A named preference part that controls the highlighting of interfaces.
159      *
160      * @since 3.2
161      */

162     public static final String JavaDoc INTERFACE="interface"; //$NON-NLS-1$
163

164     /**
165      * A named preference part that controls the highlighting of annotations.
166      *
167      * @since 3.2
168      */

169     public static final String JavaDoc ANNOTATION="annotation"; //$NON-NLS-1$
170

171     /**
172      * A named preference part that controls the highlighting of type arguments.
173      *
174      * @since 3.2
175      */

176     public static final String JavaDoc TYPE_ARGUMENT="typeArgument"; //$NON-NLS-1$
177

178     /**
179      * Semantic highlightings
180      */

181     private static SemanticHighlighting[] fgSemanticHighlightings;
182
183     /**
184      * Semantic highlighting for static final fields.
185      */

186     private static final class StaticFinalFieldHighlighting extends SemanticHighlighting {
187
188         /*
189          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
190          */

191         public String JavaDoc getPreferenceKey() {
192             return STATIC_FINAL_FIELD;
193         }
194
195         /*
196          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
197          */

198         public RGB getDefaultDefaultTextColor() {
199             return new RGB(0, 0, 0);
200         }
201
202         /*
203          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
204          */

205         public boolean isBoldByDefault() {
206             return false;
207         }
208
209         /*
210          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
211          */

212         public boolean isItalicByDefault() {
213             return false;
214         }
215
216         /*
217          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
218          */

219         public boolean isEnabledByDefault() {
220             return false;
221         }
222
223         /*
224          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
225          */

226         public String JavaDoc getDisplayName() {
227             return JavaEditorMessages.SemanticHighlighting_staticFinalField;
228         }
229
230         /*
231          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
232          */

233         public boolean consumes(SemanticToken token) {
234             IBinding binding= token.getBinding();
235             return binding != null && binding.getKind() == IBinding.VARIABLE && ((IVariableBinding)binding).isField() && (binding.getModifiers() & (Modifier.FINAL | Modifier.STATIC)) == (Modifier.FINAL | Modifier.STATIC);
236         }
237     }
238
239     /**
240      * Semantic highlighting for static fields.
241      */

242     private static final class StaticFieldHighlighting extends SemanticHighlighting {
243
244         /*
245          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
246          */

247         public String JavaDoc getPreferenceKey() {
248             return STATIC_FIELD;
249         }
250
251         /*
252          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
253          */

254         public RGB getDefaultDefaultTextColor() {
255             return new RGB(0, 0, 192);
256         }
257
258         /*
259          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
260          */

261         public boolean isBoldByDefault() {
262             return false;
263         }
264
265         /*
266          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
267          */

268         public boolean isItalicByDefault() {
269             return true;
270         }
271
272         /*
273          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
274          */

275         public boolean isEnabledByDefault() {
276             return true;
277         }
278
279         /*
280          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
281          */

282         public String JavaDoc getDisplayName() {
283             return JavaEditorMessages.SemanticHighlighting_staticField;
284         }
285
286         /*
287          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
288          */

289         public boolean consumes(SemanticToken token) {
290             IBinding binding= token.getBinding();
291             return binding != null && binding.getKind() == IBinding.VARIABLE && ((IVariableBinding)binding).isField() && (binding.getModifiers() & Modifier.STATIC) == Modifier.STATIC;
292         }
293     }
294
295     /**
296      * Semantic highlighting for fields.
297      */

298     private static final class FieldHighlighting extends SemanticHighlighting {
299
300         /*
301          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
302          */

303         public String JavaDoc getPreferenceKey() {
304             return FIELD;
305         }
306
307         /*
308          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
309          */

310         public RGB getDefaultDefaultTextColor() {
311             return new RGB(0, 0, 192);
312         }
313
314         /*
315          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
316          */

317         public boolean isBoldByDefault() {
318             return false;
319         }
320
321         /*
322          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
323          */

324         public boolean isItalicByDefault() {
325             return false;
326         }
327
328         /*
329          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
330          */

331         public boolean isEnabledByDefault() {
332             return true;
333         }
334
335         /*
336          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
337          */

338         public String JavaDoc getDisplayName() {
339             return JavaEditorMessages.SemanticHighlighting_field;
340         }
341
342         /*
343          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
344          */

345         public boolean consumes(SemanticToken token) {
346             IBinding binding= token.getBinding();
347             return binding != null && binding.getKind() == IBinding.VARIABLE && ((IVariableBinding)binding).isField();
348         }
349     }
350
351     /**
352      * Semantic highlighting for auto(un)boxed expressions.
353      */

354     private static final class AutoboxHighlighting extends SemanticHighlighting {
355
356         /*
357          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
358          */

359         public String JavaDoc getPreferenceKey() {
360             return AUTOBOXING;
361         }
362
363         /*
364          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
365          */

366         public RGB getDefaultDefaultTextColor() {
367             return new RGB(171, 48, 0);
368         }
369
370         /*
371          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
372          */

373         public boolean isBoldByDefault() {
374             return false;
375         }
376
377         /*
378          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
379          */

380         public boolean isItalicByDefault() {
381             return false;
382         }
383
384         /*
385          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
386          */

387         public boolean isEnabledByDefault() {
388             return false;
389         }
390
391         /*
392          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
393          */

394         public String JavaDoc getDisplayName() {
395             return JavaEditorMessages.SemanticHighlighting_autoboxing;
396         }
397         
398         /*
399          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumesLiteral(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
400          */

401         public boolean consumesLiteral(SemanticToken token) {
402             return isAutoUnBoxing(token.getLiteral());
403         }
404
405         /*
406          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
407          */

408         public boolean consumes(SemanticToken token) {
409             return isAutoUnBoxing(token.getNode());
410         }
411
412         private boolean isAutoUnBoxing(Expression node) {
413             if (isAutoUnBoxingExpression(node))
414                 return true;
415             // special cases: the autoboxing conversions happens at a
416
// location that is not mapped directly to a simple name
417
// or a literal, but can still be mapped somehow
418
// A) expressions
419
StructuralPropertyDescriptor desc= node.getLocationInParent();
420             if (desc == ArrayAccess.ARRAY_PROPERTY
421                     || desc == InfixExpression.LEFT_OPERAND_PROPERTY
422                     || desc == InfixExpression.RIGHT_OPERAND_PROPERTY
423                     || desc == ConditionalExpression.THEN_EXPRESSION_PROPERTY
424                     || desc == PrefixExpression.OPERAND_PROPERTY
425                     || desc == CastExpression.EXPRESSION_PROPERTY
426                     || desc == ConditionalExpression.ELSE_EXPRESSION_PROPERTY) {
427                 ASTNode parent= node.getParent();
428                 if (parent instanceof Expression)
429                     return isAutoUnBoxingExpression((Expression) parent);
430             }
431             // B) constructor invocations
432
if (desc == SimpleType.NAME_PROPERTY || desc == QualifiedType.NAME_PROPERTY) {
433                 ASTNode parent= node.getParent();
434                 if (parent != null && parent.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY) {
435                     parent= parent.getParent();
436                     if (parent instanceof Expression)
437                         return isAutoUnBoxingExpression((Expression) parent);
438                 }
439             }
440             return false;
441         }
442         
443         private boolean isAutoUnBoxingExpression(Expression expression) {
444             return expression.resolveBoxing() || expression.resolveUnboxing();
445         }
446     }
447
448     /**
449      * Semantic highlighting for method declarations.
450      */

451     private static final class MethodDeclarationHighlighting extends SemanticHighlighting {
452
453         /*
454          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
455          */

456         public String JavaDoc getPreferenceKey() {
457             return METHOD_DECLARATION;
458         }
459
460         /*
461          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
462          */

463         public RGB getDefaultDefaultTextColor() {
464             return new RGB(0, 0, 0);
465         }
466
467         /*
468          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
469          */

470         public boolean isBoldByDefault() {
471             return true;
472         }
473
474         /*
475          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
476          */

477         public boolean isItalicByDefault() {
478             return false;
479         }
480
481         /*
482          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
483          */

484         public boolean isEnabledByDefault() {
485             return false;
486         }
487
488         /*
489          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
490          */

491         public String JavaDoc getDisplayName() {
492             return JavaEditorMessages.SemanticHighlighting_methodDeclaration;
493         }
494
495         /*
496          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#isMatched(org.eclipse.jdt.core.dom.ASTNode)
497          */

498         public boolean consumes(SemanticToken token) {
499             StructuralPropertyDescriptor location= token.getNode().getLocationInParent();
500             return location == MethodDeclaration.NAME_PROPERTY || location == AnnotationTypeMemberDeclaration.NAME_PROPERTY;
501         }
502     }
503
504     /**
505      * Semantic highlighting for static method invocations.
506      */

507     private static final class StaticMethodInvocationHighlighting extends SemanticHighlighting {
508
509         /*
510          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
511          */

512         public String JavaDoc getPreferenceKey() {
513             return STATIC_METHOD_INVOCATION;
514         }
515
516         /*
517          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
518          */

519         public RGB getDefaultDefaultTextColor() {
520             return new RGB(0, 0, 0);
521         }
522
523         /*
524          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
525          */

526         public boolean isBoldByDefault() {
527             return false;
528         }
529
530         /*
531          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
532          */

533         public boolean isItalicByDefault() {
534             return true;
535         }
536
537         /*
538          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
539          */

540         public boolean isEnabledByDefault() {
541             return true;
542         }
543
544         /*
545          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
546          */

547         public String JavaDoc getDisplayName() {
548             return JavaEditorMessages.SemanticHighlighting_staticMethodInvocation;
549         }
550
551         /*
552          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#isMatched(org.eclipse.jdt.core.dom.ASTNode)
553          */

554         public boolean consumes(SemanticToken token) {
555             SimpleName node= token.getNode();
556             if (node.isDeclaration())
557                 return false;
558
559             IBinding binding= token.getBinding();
560             return binding != null && binding.getKind() == IBinding.METHOD && (binding.getModifiers() & Modifier.STATIC) == Modifier.STATIC;
561         }
562     }
563
564     /**
565      * Semantic highlighting for annotation element references.
566      * @since 3.1
567      */

568     private static final class AnnotationElementReferenceHighlighting extends SemanticHighlighting {
569
570         /*
571          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
572          */

573         public String JavaDoc getPreferenceKey() {
574             return ANNOTATION_ELEMENT_REFERENCE;
575         }
576
577         /*
578          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
579          */

580         public RGB getDefaultDefaultTextColor() {
581             return new RGB(0, 0, 0);
582         }
583
584         /*
585          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
586          */

587         public boolean isBoldByDefault() {
588             return false;
589         }
590
591         /*
592          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
593          */

594         public boolean isItalicByDefault() {
595             return false;
596         }
597
598         /*
599          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
600          */

601         public boolean isEnabledByDefault() {
602             return false;
603         }
604
605         /*
606          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
607          */

608         public String JavaDoc getDisplayName() {
609             return JavaEditorMessages.SemanticHighlighting_annotationElementReference;
610         }
611
612         /*
613          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#isMatched(org.eclipse.jdt.core.dom.ASTNode)
614          */

615         public boolean consumes(SemanticToken token) {
616             SimpleName node= token.getNode();
617             if (node.getParent() instanceof MemberValuePair) {
618                 IBinding binding= token.getBinding();
619                 boolean isAnnotationElement= binding != null && binding.getKind() == IBinding.METHOD;
620
621                 return isAnnotationElement;
622             }
623
624             return false;
625         }
626     }
627
628     /**
629      * Semantic highlighting for abstract method invocations.
630      */

631     private static final class AbstractMethodInvocationHighlighting extends SemanticHighlighting {
632
633         /*
634          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
635          */

636         public String JavaDoc getPreferenceKey() {
637             return ABSTRACT_METHOD_INVOCATION;
638         }
639
640         /*
641          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
642          */

643         public RGB getDefaultDefaultTextColor() {
644             return new RGB(0, 0, 0);
645         }
646
647         /*
648          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
649          */

650         public boolean isBoldByDefault() {
651             return false;
652         }
653
654         /*
655          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
656          */

657         public boolean isItalicByDefault() {
658             return false;
659         }
660
661         /*
662          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
663          */

664         public boolean isEnabledByDefault() {
665             return false;
666         }
667
668         /*
669          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
670          */

671         public String JavaDoc getDisplayName() {
672             return JavaEditorMessages.SemanticHighlighting_abstractMethodInvocation;
673         }
674
675         /*
676          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#isMatched(org.eclipse.jdt.core.dom.ASTNode)
677          */

678         public boolean consumes(SemanticToken token) {
679             SimpleName node= token.getNode();
680             if (node.isDeclaration())
681                 return false;
682
683             IBinding binding= token.getBinding();
684             boolean isAbstractMethod= binding != null && binding.getKind() == IBinding.METHOD && (binding.getModifiers() & Modifier.ABSTRACT) == Modifier.ABSTRACT;
685             if (!isAbstractMethod)
686                 return false;
687
688             // filter out annotation value references
689
if (binding != null) {
690                 ITypeBinding declaringType= ((IMethodBinding)binding).getDeclaringClass();
691                 if (declaringType.isAnnotation())
692                     return false;
693             }
694
695             return true;
696         }
697     }
698
699     /**
700      * Semantic highlighting for inherited method invocations.
701      */

702     private static final class InheritedMethodInvocationHighlighting extends SemanticHighlighting {
703
704         /*
705          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
706          */

707         public String JavaDoc getPreferenceKey() {
708             return INHERITED_METHOD_INVOCATION;
709         }
710
711         /*
712          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
713          */

714         public RGB getDefaultDefaultTextColor() {
715             return new RGB(0, 0, 0);
716         }
717
718         /*
719          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
720          */

721         public boolean isBoldByDefault() {
722             return false;
723         }
724
725         /*
726          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
727          */

728         public boolean isItalicByDefault() {
729             return false;
730         }
731
732         /*
733          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
734          */

735         public boolean isEnabledByDefault() {
736             return false;
737         }
738
739         /*
740          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
741          */

742         public String JavaDoc getDisplayName() {
743             return JavaEditorMessages.SemanticHighlighting_inheritedMethodInvocation;
744         }
745
746         /*
747          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#isMatched(org.eclipse.jdt.core.dom.ASTNode)
748          */

749         public boolean consumes(SemanticToken token) {
750             SimpleName node= token.getNode();
751             if (node.isDeclaration())
752                 return false;
753
754             IBinding binding= token.getBinding();
755             if (binding == null || binding.getKind() != IBinding.METHOD)
756                 return false;
757
758             ITypeBinding currentType= Bindings.getBindingOfParentType(node);
759             ITypeBinding declaringType= ((IMethodBinding) binding).getDeclaringClass();
760             if (currentType == declaringType || currentType == null)
761                 return false;
762
763             return Bindings.isSuperType(declaringType, currentType);
764         }
765     }
766
767     /**
768      * Semantic highlighting for inherited method invocations.
769      */

770     private static final class MethodHighlighting extends SemanticHighlighting {
771
772         /*
773          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
774          */

775         public String JavaDoc getPreferenceKey() {
776             return METHOD;
777         }
778
779         /*
780          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
781          */

782         public RGB getDefaultDefaultTextColor() {
783             return new RGB(0, 0, 0);
784         }
785
786         /*
787          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
788          */

789         public boolean isBoldByDefault() {
790             return false;
791         }
792
793         /*
794          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
795          */

796         public boolean isItalicByDefault() {
797             return false;
798         }
799
800         /*
801          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
802          */

803         public boolean isEnabledByDefault() {
804             return false;
805         }
806
807         /*
808          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
809          */

810         public String JavaDoc getDisplayName() {
811             return JavaEditorMessages.SemanticHighlighting_method;
812         }
813
814         /*
815          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#isMatched(org.eclipse.jdt.core.dom.ASTNode)
816          */

817         public boolean consumes(SemanticToken token) {
818             IBinding binding= getMethodBinding(token);
819             return binding != null && binding.getKind() == IBinding.METHOD;
820         }
821
822         /**
823          * Extracts the method binding from the token's simple name. The method
824          * binding is either the token's binding (if the parent of token is a
825          * method call or declaration) or the constructor binding of a class
826          * instance creation if the node is the type name of a class instance
827          * creation.
828          *
829          * @param token the token to extract the method binding from
830          * @return the corresponding method binding, or <code>null</code>
831          */

832         private IBinding getMethodBinding(SemanticToken token) {
833             IBinding binding= null;
834             // work around: https://bugs.eclipse.org/bugs/show_bug.cgi?id=62605
835
ASTNode node= token.getNode();
836             ASTNode parent= node.getParent();
837             while (isTypePath(node, parent)) {
838                 node= parent;
839                 parent= parent.getParent();
840             }
841
842             if (parent != null && node.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY)
843                 binding= ((ClassInstanceCreation) parent).resolveConstructorBinding();
844             else
845                 binding= token.getBinding();
846             return binding;
847         }
848
849         /**
850          * Returns <code>true</code> if the given child/parent nodes are valid
851          * sub nodes of a <code>Type</code> ASTNode.
852          * @param child the child node
853          * @param parent the parent node
854          * @return <code>true</code> if the nodes may be the sub nodes of a type node, false otherwise
855          */

856         private boolean isTypePath(ASTNode child, ASTNode parent) {
857             if (parent instanceof Type) {
858                 StructuralPropertyDescriptor location= child.getLocationInParent();
859                 return location == ParameterizedType.TYPE_PROPERTY || location == SimpleType.NAME_PROPERTY;
860             } else if (parent instanceof QualifiedName) {
861                 StructuralPropertyDescriptor location= child.getLocationInParent();
862                 return location == QualifiedName.NAME_PROPERTY;
863             }
864             return false;
865         }
866     }
867
868     /**
869      * Semantic highlighting for local variable declarations.
870      */

871     private static final class LocalVariableDeclarationHighlighting extends SemanticHighlighting {
872
873         /*
874          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
875          */

876         public String JavaDoc getPreferenceKey() {
877             return LOCAL_VARIABLE_DECLARATION;
878         }
879
880         /*
881          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
882          */

883         public RGB getDefaultDefaultTextColor() {
884             return new RGB(0, 0, 0);
885         }
886
887         /*
888          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
889          */

890         public boolean isBoldByDefault() {
891             return false;
892         }
893
894         /*
895          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
896          */

897         public boolean isItalicByDefault() {
898             return false;
899         }
900
901         /*
902          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
903          */

904         public boolean isEnabledByDefault() {
905             return false;
906         }
907
908         /*
909          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
910          */

911         public String JavaDoc getDisplayName() {
912             return JavaEditorMessages.SemanticHighlighting_localVariableDeclaration;
913         }
914
915         /*
916          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
917          */

918         public boolean consumes(SemanticToken token) {
919             SimpleName node= token.getNode();
920             StructuralPropertyDescriptor location= node.getLocationInParent();
921             if (location == VariableDeclarationFragment.NAME_PROPERTY || location == SingleVariableDeclaration.NAME_PROPERTY) {
922                 ASTNode parent= node.getParent();
923                 if (parent instanceof VariableDeclaration) {
924                     parent= parent.getParent();
925                     return parent == null || !(parent instanceof FieldDeclaration);
926                 }
927             }
928             return false;
929         }
930     }
931
932     /**
933      * Semantic highlighting for local variables.
934      */

935     private static final class LocalVariableHighlighting extends SemanticHighlighting {
936
937         /*
938          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
939          */

940         public String JavaDoc getPreferenceKey() {
941             return LOCAL_VARIABLE;
942         }
943
944         /*
945          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
946          */

947         public RGB getDefaultDefaultTextColor() {
948             return new RGB(0, 0, 0);
949         }
950
951         /*
952          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
953          */

954         public boolean isBoldByDefault() {
955             return false;
956         }
957
958         /*
959          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
960          */

961         public boolean isItalicByDefault() {
962             return false;
963         }
964
965         /*
966          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
967          */

968         public boolean isEnabledByDefault() {
969             return false;
970         }
971
972         /*
973          * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
974          */

975         public String JavaDoc getDisplayName() {
976             return JavaEditorMessages.SemanticHighlighting_localVariable;
977         }
978
979         /*
980          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
981          */

982         public boolean consumes(SemanticToken token) {
983             IBinding binding= token.getBinding();
984             if (binding != null && binding.getKind() == IBinding.VARIABLE && !((IVariableBinding) binding).isField()) {
985                 ASTNode decl= token.getRoot().findDeclaringNode(binding);
986                 return decl instanceof VariableDeclaration;
987             }
988             return false;
989         }
990     }
991
992     /**
993      * Semantic highlighting for parameter variables.
994      */

995     private static final class ParameterVariableHighlighting extends SemanticHighlighting {
996
997         /*
998          * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
999          */

1000        public String JavaDoc getPreferenceKey() {
1001            return PARAMETER_VARIABLE;
1002        }
1003
1004        /*
1005         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
1006         */

1007        public RGB getDefaultDefaultTextColor() {
1008            return new RGB(0, 0, 0);
1009        }
1010
1011        /*
1012         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
1013         */

1014        public boolean isBoldByDefault() {
1015            return false;
1016        }
1017
1018        /*
1019         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
1020         */

1021        public boolean isItalicByDefault() {
1022            return false;
1023        }
1024
1025        /*
1026         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
1027         */

1028        public boolean isEnabledByDefault() {
1029            return false;
1030        }
1031
1032        /*
1033         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
1034         */

1035        public String JavaDoc getDisplayName() {
1036            return JavaEditorMessages.SemanticHighlighting_parameterVariable;
1037        }
1038
1039        /*
1040         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
1041         */

1042        public boolean consumes(SemanticToken token) {
1043            IBinding binding= token.getBinding();
1044            if (binding != null && binding.getKind() == IBinding.VARIABLE && !((IVariableBinding) binding).isField()) {
1045                ASTNode decl= token.getRoot().findDeclaringNode(binding);
1046                return decl != null && decl.getLocationInParent() == MethodDeclaration.PARAMETERS_PROPERTY;
1047            }
1048            return false;
1049        }
1050    }
1051
1052    /**
1053     * Semantic highlighting for deprecated members.
1054     */

1055    private static final class DeprecatedMemberHighlighting extends SemanticHighlighting {
1056
1057        /*
1058         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
1059         */

1060        public String JavaDoc getPreferenceKey() {
1061            return DEPRECATED_MEMBER;
1062        }
1063
1064        /*
1065         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
1066         */

1067        public RGB getDefaultDefaultTextColor() {
1068            return new RGB(0, 0, 0);
1069        }
1070
1071        /*
1072         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
1073         */

1074        public boolean isBoldByDefault() {
1075            return false;
1076        }
1077
1078        /*
1079         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
1080         */

1081        public boolean isItalicByDefault() {
1082            return false;
1083        }
1084
1085        /*
1086         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isStrikethroughByDefault()
1087         * @since 3.1
1088         */

1089        public boolean isStrikethroughByDefault() {
1090            return true;
1091        }
1092
1093        /*
1094         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
1095         */

1096        public boolean isEnabledByDefault() {
1097            return true;
1098        }
1099
1100        /*
1101         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
1102         */

1103        public String JavaDoc getDisplayName() {
1104            return JavaEditorMessages.SemanticHighlighting_deprecatedMember;
1105        }
1106
1107        /*
1108         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
1109         */

1110        public boolean consumes(SemanticToken token) {
1111            IBinding binding= getMethodBinding(token);
1112            return binding != null ? binding.isDeprecated() : false;
1113        }
1114
1115        /**
1116         * Extracts the method binding from the token's simple name. The method
1117         * binding is either the token's binding (if the parent of token is a
1118         * method call or declaration) or the constructor binding of a class
1119         * instance creation if the node is the type name of a class instance
1120         * creation.
1121         *
1122         * @param token the token to extract the method binding from
1123         * @return the corresponding method binding, or <code>null</code>
1124         */

1125        private IBinding getMethodBinding(SemanticToken token) {
1126            IBinding binding= null;
1127            // work around: https://bugs.eclipse.org/bugs/show_bug.cgi?id=62605
1128
ASTNode node= token.getNode();
1129            ASTNode parent= node.getParent();
1130            while (isTypePath(node, parent)) {
1131                node= parent;
1132                parent= parent.getParent();
1133            }
1134
1135            if (parent != null && node.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY)
1136                binding= ((ClassInstanceCreation) parent).resolveConstructorBinding();
1137            else
1138                binding= token.getBinding();
1139            return binding;
1140        }
1141
1142        /**
1143         * Returns <code>true</code> if the given child/parent nodes are valid
1144         * sub nodes of a <code>Type</code> ASTNode.
1145         * @param child the child node
1146         * @param parent the parent node
1147         * @return <code>true</code> if the nodes may be the sub nodes of a type node, false otherwise
1148         */

1149        private boolean isTypePath(ASTNode child, ASTNode parent) {
1150            if (parent instanceof Type) {
1151                StructuralPropertyDescriptor location= child.getLocationInParent();
1152                return location == ParameterizedType.TYPE_PROPERTY || location == SimpleType.NAME_PROPERTY;
1153            } else if (parent instanceof QualifiedName) {
1154                StructuralPropertyDescriptor location= child.getLocationInParent();
1155                return location == QualifiedName.NAME_PROPERTY;
1156            }
1157            return false;
1158        }
1159    }
1160
1161    /**
1162     * Semantic highlighting for type variables.
1163     * @since 3.1
1164     */

1165    private static final class TypeVariableHighlighting extends SemanticHighlighting {
1166
1167        /*
1168         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
1169         */

1170        public String JavaDoc getPreferenceKey() {
1171            return TYPE_VARIABLE;
1172        }
1173
1174        /*
1175         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
1176         */

1177        public RGB getDefaultDefaultTextColor() {
1178            return new RGB(100, 70, 50);
1179        }
1180
1181        /*
1182         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
1183         */

1184        public boolean isBoldByDefault() {
1185            return true;
1186        }
1187
1188        /*
1189         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
1190         */

1191        public boolean isItalicByDefault() {
1192            return false;
1193        }
1194
1195        /*
1196         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
1197         */

1198        public boolean isEnabledByDefault() {
1199            return false;
1200        }
1201
1202        /*
1203         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
1204         */

1205        public String JavaDoc getDisplayName() {
1206            return JavaEditorMessages.SemanticHighlighting_typeVariables;
1207        }
1208
1209        /*
1210         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
1211         */

1212        public boolean consumes(SemanticToken token) {
1213
1214            // 1: match types in type parameter lists
1215
SimpleName name= token.getNode();
1216            ASTNode node= name.getParent();
1217            if (node.getNodeType() != ASTNode.SIMPLE_TYPE && node.getNodeType() != ASTNode.TYPE_PARAMETER)
1218                return false;
1219
1220            // 2: match generic type variable references
1221
IBinding binding= token.getBinding();
1222            return binding instanceof ITypeBinding && ((ITypeBinding) binding).isTypeVariable();
1223        }
1224    }
1225    
1226    /**
1227     * Semantic highlighting for classes.
1228     * @since 3.2
1229     */

1230    private static final class ClassHighlighting extends SemanticHighlighting {
1231
1232        /*
1233         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
1234         */

1235        public String JavaDoc getPreferenceKey() {
1236            return CLASS;
1237        }
1238
1239        /*
1240         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
1241         */

1242        public RGB getDefaultDefaultTextColor() {
1243            return new RGB(0, 80, 50);
1244        }
1245
1246        /*
1247         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
1248         */

1249        public boolean isBoldByDefault() {
1250            return false;
1251        }
1252
1253        /*
1254         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
1255         */

1256        public boolean isItalicByDefault() {
1257            return false;
1258        }
1259
1260        /*
1261         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
1262         */

1263        public boolean isEnabledByDefault() {
1264            return false;
1265        }
1266
1267        /*
1268         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
1269         */

1270        public String JavaDoc getDisplayName() {
1271            return JavaEditorMessages.SemanticHighlighting_classes;
1272        }
1273
1274        /*
1275         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
1276         */

1277        public boolean consumes(SemanticToken token) {
1278
1279            // 1: match types
1280
SimpleName name= token.getNode();
1281            ASTNode node= name.getParent();
1282            int nodeType= node.getNodeType();
1283            if (nodeType != ASTNode.SIMPLE_TYPE && nodeType != ASTNode.THIS_EXPRESSION && nodeType != ASTNode.QUALIFIED_TYPE && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.TYPE_DECLARATION)
1284                return false;
1285            while (nodeType == ASTNode.QUALIFIED_NAME) {
1286                node= node.getParent();
1287                nodeType= node.getNodeType();
1288                if (nodeType == ASTNode.IMPORT_DECLARATION)
1289                    return false;
1290            }
1291
1292            // 2: match classes
1293
IBinding binding= token.getBinding();
1294            return binding instanceof ITypeBinding && ((ITypeBinding) binding).isClass();
1295        }
1296    }
1297
1298    /**
1299     * Semantic highlighting for enums.
1300     * @since 3.2
1301     */

1302    private static final class EnumHighlighting extends SemanticHighlighting {
1303        
1304        /*
1305         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
1306         */

1307        public String JavaDoc getPreferenceKey() {
1308            return ENUM;
1309        }
1310        
1311        /*
1312         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
1313         */

1314        public RGB getDefaultDefaultTextColor() {
1315            return new RGB(100, 70, 50);
1316        }
1317        
1318        /*
1319         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
1320         */

1321        public boolean isBoldByDefault() {
1322            return false;
1323        }
1324        
1325        /*
1326         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
1327         */

1328        public boolean isItalicByDefault() {
1329            return false;
1330        }
1331        
1332        /*
1333         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
1334         */

1335        public boolean isEnabledByDefault() {
1336            return false;
1337        }
1338        
1339        /*
1340         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
1341         */

1342        public String JavaDoc getDisplayName() {
1343            return JavaEditorMessages.SemanticHighlighting_enums;
1344        }
1345        
1346        /*
1347         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
1348         */

1349        public boolean consumes(SemanticToken token) {
1350            
1351            // 1: match types
1352
SimpleName name= token.getNode();
1353            ASTNode node= name.getParent();
1354            int nodeType= node.getNodeType();
1355            if (nodeType != ASTNode.SIMPLE_TYPE && nodeType != ASTNode.QUALIFIED_TYPE && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.ENUM_DECLARATION)
1356                return false;
1357            while (nodeType == ASTNode.QUALIFIED_NAME) {
1358                node= node.getParent();
1359                nodeType= node.getNodeType();
1360                if (nodeType == ASTNode.IMPORT_DECLARATION)
1361                    return false;
1362            }
1363
1364            // 2: match enums
1365
IBinding binding= token.getBinding();
1366            return binding instanceof ITypeBinding && ((ITypeBinding) binding).isEnum();
1367        }
1368    }
1369    
1370    /**
1371     * Semantic highlighting for interfaces.
1372     * @since 3.2
1373     */

1374    private static final class InterfaceHighlighting extends SemanticHighlighting {
1375        
1376        /*
1377         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
1378         */

1379        public String JavaDoc getPreferenceKey() {
1380            return INTERFACE;
1381        }
1382        
1383        /*
1384         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
1385         */

1386        public RGB getDefaultDefaultTextColor() {
1387            return new RGB(50, 63, 112);
1388        }
1389        
1390        /*
1391         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
1392         */

1393        public boolean isBoldByDefault() {
1394            return false;
1395        }
1396        
1397        /*
1398         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
1399         */

1400        public boolean isItalicByDefault() {
1401            return false;
1402        }
1403        
1404        /*
1405         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
1406         */

1407        public boolean isEnabledByDefault() {
1408            return false;
1409        }
1410        
1411        /*
1412         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
1413         */

1414        public String JavaDoc getDisplayName() {
1415            return JavaEditorMessages.SemanticHighlighting_interfaces;
1416        }
1417        
1418        /*
1419         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
1420         */

1421        public boolean consumes(SemanticToken token) {
1422            
1423            // 1: match types
1424
SimpleName name= token.getNode();
1425            ASTNode node= name.getParent();
1426            int nodeType= node.getNodeType();
1427            if (nodeType != ASTNode.SIMPLE_TYPE && nodeType != ASTNode.QUALIFIED_TYPE && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.TYPE_DECLARATION)
1428                return false;
1429            while (nodeType == ASTNode.QUALIFIED_NAME) {
1430                node= node.getParent();
1431                nodeType= node.getNodeType();
1432                if (nodeType == ASTNode.IMPORT_DECLARATION)
1433                    return false;
1434            }
1435
1436            // 2: match interfaces
1437
IBinding binding= token.getBinding();
1438            return binding instanceof ITypeBinding && ((ITypeBinding) binding).isInterface();
1439        }
1440    }
1441    
1442    /**
1443     * Semantic highlighting for annotation types.
1444     * @since 3.2
1445     */

1446    private static final class AnnotationHighlighting extends SemanticHighlighting {
1447        
1448        /*
1449         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
1450         */

1451        public String JavaDoc getPreferenceKey() {
1452            return ANNOTATION;
1453        }
1454        
1455        /*
1456         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
1457         */

1458        public RGB getDefaultDefaultTextColor() {
1459            return new RGB(100, 100, 100);
1460        }
1461        
1462        /*
1463         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
1464         */

1465        public boolean isBoldByDefault() {
1466            return false;
1467        }
1468        
1469        /*
1470         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
1471         */

1472        public boolean isItalicByDefault() {
1473            return false;
1474        }
1475        
1476        /*
1477         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
1478         */

1479        public boolean isEnabledByDefault() {
1480            return true; // as it replaces the syntax based highlighting which is always enabled
1481
}
1482        
1483        /*
1484         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
1485         */

1486        public String JavaDoc getDisplayName() {
1487            return JavaEditorMessages.SemanticHighlighting_annotations;
1488        }
1489        
1490        /*
1491         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
1492         */

1493        public boolean consumes(SemanticToken token) {
1494            
1495            // 1: match types
1496
SimpleName name= token.getNode();
1497            ASTNode node= name.getParent();
1498            int nodeType= node.getNodeType();
1499            if (nodeType != ASTNode.SIMPLE_TYPE && nodeType != ASTNode.QUALIFIED_TYPE && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.ANNOTATION_TYPE_DECLARATION
1500                    && nodeType != ASTNode.MARKER_ANNOTATION && nodeType != ASTNode.NORMAL_ANNOTATION && nodeType != ASTNode.SINGLE_MEMBER_ANNOTATION)
1501                return false;
1502            while (nodeType == ASTNode.QUALIFIED_NAME) {
1503                node= node.getParent();
1504                nodeType= node.getNodeType();
1505                if (nodeType == ASTNode.IMPORT_DECLARATION)
1506                    return false;
1507            }
1508
1509            // 2: match annotations
1510
IBinding binding= token.getBinding();
1511            return binding instanceof ITypeBinding && ((ITypeBinding) binding).isAnnotation();
1512        }
1513    }
1514    
1515    /**
1516     * Semantic highlighting for annotation types.
1517     * @since 3.2
1518     */

1519    private static final class TypeArgumentHighlighting extends SemanticHighlighting {
1520        
1521        /*
1522         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#getPreferenceKey()
1523         */

1524        public String JavaDoc getPreferenceKey() {
1525            return TYPE_ARGUMENT;
1526        }
1527        
1528        /*
1529         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextColor()
1530         */

1531        public RGB getDefaultDefaultTextColor() {
1532            return new RGB(13, 100, 0);
1533        }
1534        
1535        /*
1536         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDefaultTextStyleBold()
1537         */

1538        public boolean isBoldByDefault() {
1539            return false;
1540        }
1541        
1542        /*
1543         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isItalicByDefault()
1544         */

1545        public boolean isItalicByDefault() {
1546            return false;
1547        }
1548        
1549        /*
1550         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#isEnabledByDefault()
1551         */

1552        public boolean isEnabledByDefault() {
1553            return false;
1554        }
1555        
1556        /*
1557         * @see org.eclipse.jdt.internal.ui.javaeditor.ISemanticHighlighting#getDisplayName()
1558         */

1559        public String JavaDoc getDisplayName() {
1560            return JavaEditorMessages.SemanticHighlighting_typeArguments;
1561        }
1562        
1563        /*
1564         * @see org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlighting#consumes(org.eclipse.jdt.internal.ui.javaeditor.SemanticToken)
1565         */

1566        public boolean consumes(SemanticToken token) {
1567            
1568            // 1: match types
1569
SimpleName name= token.getNode();
1570            ASTNode node= name.getParent();
1571            int nodeType= node.getNodeType();
1572            if (nodeType != ASTNode.SIMPLE_TYPE && nodeType != ASTNode.QUALIFIED_TYPE)
1573                return false;
1574            
1575            // 2: match type arguments
1576
StructuralPropertyDescriptor locationInParent= node.getLocationInParent();
1577            if (locationInParent == ParameterizedType.TYPE_ARGUMENTS_PROPERTY)
1578                return true;
1579            
1580            return false;
1581        }
1582    }
1583    
1584    /**
1585     * A named preference that controls the given semantic highlighting's color.
1586     *
1587     * @param semanticHighlighting the semantic highlighting
1588     * @return the color preference key
1589     */

1590    public static String JavaDoc getColorPreferenceKey(SemanticHighlighting semanticHighlighting) {
1591        return PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + semanticHighlighting.getPreferenceKey() + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_COLOR_SUFFIX;
1592    }
1593
1594    /**
1595     * A named preference that controls if the given semantic highlighting has the text attribute bold.
1596     *
1597     * @param semanticHighlighting the semantic highlighting
1598     * @return the bold preference key
1599     */

1600    public static String JavaDoc getBoldPreferenceKey(SemanticHighlighting semanticHighlighting) {
1601        return PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + semanticHighlighting.getPreferenceKey() + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_BOLD_SUFFIX;
1602    }
1603
1604    /**
1605     * A named preference that controls if the given semantic highlighting has the text attribute italic.
1606     *
1607     * @param semanticHighlighting the semantic highlighting
1608     * @return the italic preference key
1609     */

1610    public static String JavaDoc getItalicPreferenceKey(SemanticHighlighting semanticHighlighting) {
1611        return PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + semanticHighlighting.getPreferenceKey() + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_ITALIC_SUFFIX;
1612    }
1613
1614    /**
1615     * A named preference that controls if the given semantic highlighting has the text attribute strikethrough.
1616     *
1617     * @param semanticHighlighting the semantic highlighting
1618     * @return the strikethrough preference key
1619     * @since 3.1
1620     */

1621    public static String JavaDoc getStrikethroughPreferenceKey(SemanticHighlighting semanticHighlighting) {
1622        return PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + semanticHighlighting.getPreferenceKey() + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_STRIKETHROUGH_SUFFIX;
1623    }
1624
1625    /**
1626     * A named preference that controls if the given semantic highlighting has the text attribute underline.
1627     *
1628     * @param semanticHighlighting the semantic highlighting
1629     * @return the underline preference key
1630     * @since 3.1
1631     */

1632    public static String JavaDoc getUnderlinePreferenceKey(SemanticHighlighting semanticHighlighting) {
1633        return PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + semanticHighlighting.getPreferenceKey() + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_UNDERLINE_SUFFIX;
1634    }
1635
1636    /**
1637     * A named preference that controls if the given semantic highlighting is enabled.
1638     *
1639     * @param semanticHighlighting the semantic highlighting
1640     * @return the enabled preference key
1641     */

1642    public static String JavaDoc getEnabledPreferenceKey(SemanticHighlighting semanticHighlighting) {
1643        return PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + semanticHighlighting.getPreferenceKey() + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_ENABLED_SUFFIX;
1644    }
1645
1646    /**
1647     * @return The semantic highlightings, the order defines the precedence of matches, the first match wins.
1648     */

1649    public static SemanticHighlighting[] getSemanticHighlightings() {
1650        if (fgSemanticHighlightings == null)
1651            fgSemanticHighlightings= new SemanticHighlighting[] {
1652                new DeprecatedMemberHighlighting(),
1653                new AutoboxHighlighting(),
1654                new StaticFinalFieldHighlighting(),
1655                new StaticFieldHighlighting(),
1656                new FieldHighlighting(),
1657                new MethodDeclarationHighlighting(),
1658                new StaticMethodInvocationHighlighting(),
1659                new AbstractMethodInvocationHighlighting(),
1660                new AnnotationElementReferenceHighlighting(),
1661                new InheritedMethodInvocationHighlighting(),
1662                new ParameterVariableHighlighting(),
1663                new LocalVariableDeclarationHighlighting(),
1664                new LocalVariableHighlighting(),
1665                new TypeVariableHighlighting(), // before type arguments!
1666
new MethodHighlighting(), // before types to get ctors
1667
new TypeArgumentHighlighting(), // before other types
1668
new ClassHighlighting(),
1669                new EnumHighlighting(),
1670                new AnnotationHighlighting(), // before interfaces
1671
new InterfaceHighlighting(),
1672            };
1673        return fgSemanticHighlightings;
1674    }
1675
1676    /**
1677     * Initialize default preferences in the given preference store.
1678     * @param store The preference store
1679     */

1680    public static void initDefaults(IPreferenceStore store) {
1681        SemanticHighlighting[] semanticHighlightings= getSemanticHighlightings();
1682        for (int i= 0, n= semanticHighlightings.length; i < n; i++) {
1683            SemanticHighlighting semanticHighlighting= semanticHighlightings[i];
1684            setDefaultAndFireEvent(store, SemanticHighlightings.getColorPreferenceKey(semanticHighlighting), semanticHighlighting.getDefaultTextColor());
1685            store.setDefault(SemanticHighlightings.getBoldPreferenceKey(semanticHighlighting), semanticHighlighting.isBoldByDefault());
1686            store.setDefault(SemanticHighlightings.getItalicPreferenceKey(semanticHighlighting), semanticHighlighting.isItalicByDefault());
1687            store.setDefault(SemanticHighlightings.getStrikethroughPreferenceKey(semanticHighlighting), semanticHighlighting.isStrikethroughByDefault());
1688            store.setDefault(SemanticHighlightings.getUnderlinePreferenceKey(semanticHighlighting), semanticHighlighting.isUnderlineByDefault());
1689            store.setDefault(SemanticHighlightings.getEnabledPreferenceKey(semanticHighlighting), semanticHighlighting.isEnabledByDefault());
1690        }
1691
1692        convertMethodHighlightingPreferences(store);
1693        convertAnnotationHighlightingPreferences(store);
1694    }
1695
1696    /**
1697     * Tests whether <code>event</code> in <code>store</code> affects the
1698     * enablement of semantic highlighting.
1699     *
1700     * @param store the preference store where <code>event</code> was observed
1701     * @param event the property change under examination
1702     * @return <code>true</code> if <code>event</code> changed semantic
1703     * highlighting enablement, <code>false</code> if it did not
1704     * @since 3.1
1705     */

1706    public static boolean affectsEnablement(IPreferenceStore store, PropertyChangeEvent event) {
1707        String JavaDoc relevantKey= null;
1708        SemanticHighlighting[] highlightings= getSemanticHighlightings();
1709        for (int i= 0; i < highlightings.length; i++) {
1710            if (event.getProperty().equals(getEnabledPreferenceKey(highlightings[i]))) {
1711                relevantKey= event.getProperty();
1712                break;
1713            }
1714        }
1715        if (relevantKey == null)
1716            return false;
1717
1718        for (int i= 0; i < highlightings.length; i++) {
1719            String JavaDoc key= getEnabledPreferenceKey(highlightings[i]);
1720            if (key.equals(relevantKey))
1721                continue;
1722            if (store.getBoolean(key))
1723                return false; // another is still enabled or was enabled before
1724
}
1725
1726        // all others are disabled, so toggling relevantKey affects the enablement
1727
return true;
1728    }
1729
1730    /**
1731     * Tests whether semantic highlighting is currently enabled.
1732     *
1733     * @param store the preference store to consult
1734     * @return <code>true</code> if semantic highlighting is enabled,
1735     * <code>false</code> if it is not
1736     * @since 3.1
1737     */

1738    public static boolean isEnabled(IPreferenceStore store) {
1739        SemanticHighlighting[] highlightings= getSemanticHighlightings();
1740        boolean enable= false;
1741        for (int i= 0; i < highlightings.length; i++) {
1742            String JavaDoc enabledKey= getEnabledPreferenceKey(highlightings[i]);
1743            if (store.getBoolean(enabledKey)) {
1744                enable= true;
1745                break;
1746            }
1747        }
1748
1749        return enable;
1750    }
1751
1752    /**
1753     * In 3.0, methods were highlighted by a rule-based word matcher that
1754     * matched any identifier that was followed by possibly white space and a
1755     * left parenthesis.
1756     * <p>
1757     * With generics, this does not work any longer for constructors of generic
1758     * types, and the highlighting has been moved to be a semantic highlighting.
1759     * Because different preference key naming schemes are used, we have to
1760     * migrate the old settings to the new ones, which is done here. Nothing
1761     * needs to be done if the old settings were set to the default values.
1762     * </p>
1763     *
1764     * @param store the preference store to migrate
1765     * @since 3.1
1766     */

1767    private static void convertMethodHighlightingPreferences(IPreferenceStore store) {
1768        String JavaDoc colorkey= PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + METHOD + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_COLOR_SUFFIX;
1769        String JavaDoc boldkey= PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + METHOD + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_BOLD_SUFFIX;
1770        String JavaDoc italickey= PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + METHOD + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_ITALIC_SUFFIX;
1771        String JavaDoc enabledkey= PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + METHOD + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_ENABLED_SUFFIX;
1772
1773        String JavaDoc oldColorkey= PreferenceConstants.EDITOR_JAVA_METHOD_NAME_COLOR;
1774        String JavaDoc oldBoldkey= PreferenceConstants.EDITOR_JAVA_METHOD_NAME_BOLD;
1775        String JavaDoc oldItalickey= PreferenceConstants.EDITOR_JAVA_METHOD_NAME_ITALIC;
1776
1777        if (conditionalReset(store, oldColorkey, colorkey)
1778                || conditionalReset(store, oldBoldkey, boldkey)
1779                || conditionalReset(store, oldItalickey, italickey)) {
1780            store.setValue(enabledkey, true);
1781        }
1782
1783    }
1784
1785    /**
1786     * In 3.1, annotations were highlighted by a rule-based word matcher that matched any identifier
1787     * preceded by an '@' sign and possibly white space.
1788     * <p>
1789     * This does not work when there is a comment between the '@' and the annotation, results in
1790     * stale highlighting if there is a new line between the '@' and the annotation, and does not
1791     * work for highlighting annotation declarations. Because different preference key naming
1792     * schemes are used, we have to migrate the old settings to the new ones, which is done here.
1793     * Nothing needs to be done if the old settings were set to the default values.
1794     * </p>
1795     *
1796     * @param store the preference store to migrate
1797     * @since 3.2
1798     */

1799    private static void convertAnnotationHighlightingPreferences(IPreferenceStore store) {
1800        String JavaDoc colorkey= PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + ANNOTATION + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_COLOR_SUFFIX;
1801        String JavaDoc boldkey= PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + ANNOTATION + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_BOLD_SUFFIX;
1802        String JavaDoc italickey= PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + ANNOTATION + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_ITALIC_SUFFIX;
1803        String JavaDoc strikethroughKey= PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + ANNOTATION + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_STRIKETHROUGH_SUFFIX;
1804        String JavaDoc underlineKey= PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + ANNOTATION + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_UNDERLINE_SUFFIX;
1805        String JavaDoc enabledkey= PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX + ANNOTATION + PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_ENABLED_SUFFIX;
1806        
1807        String JavaDoc oldColorkey= PreferenceConstants.EDITOR_JAVA_ANNOTATION_COLOR;
1808        String JavaDoc oldBoldkey= PreferenceConstants.EDITOR_JAVA_ANNOTATION_BOLD;
1809        String JavaDoc oldItalickey= PreferenceConstants.EDITOR_JAVA_ANNOTATION_ITALIC;
1810        String JavaDoc oldStrikethroughKey= PreferenceConstants.EDITOR_JAVA_ANNOTATION_STRIKETHROUGH;
1811        String JavaDoc oldUnderlineKey= PreferenceConstants.EDITOR_JAVA_ANNOTATION_UNDERLINE;
1812        
1813        if (conditionalReset(store, oldColorkey, colorkey)
1814                || conditionalReset(store, oldBoldkey, boldkey)
1815                || conditionalReset(store, oldItalickey, italickey)
1816                || conditionalReset(store, oldStrikethroughKey, strikethroughKey)
1817                || conditionalReset(store, oldUnderlineKey, underlineKey)) {
1818            store.setValue(enabledkey, true);
1819        }
1820        
1821    }
1822    
1823    /**
1824     * If the setting pointed to by <code>oldKey</code> is not the default
1825     * setting, store that setting under <code>newKey</code> and reset
1826     * <code>oldKey</code> to its default setting.
1827     * <p>
1828     * Returns <code>true</code> if any changes were made.
1829     * </p>
1830     *
1831     * @param store the preference store to read from and write to
1832     * @param oldKey the old preference key
1833     * @param newKey the new preference key
1834     * @return <code>true</code> if <code>store</code> was modified,
1835     * <code>false</code> if not
1836     * @since 3.1
1837     */

1838    private static boolean conditionalReset(IPreferenceStore store, String JavaDoc oldKey, String JavaDoc newKey) {
1839        if (!store.isDefault(oldKey)) {
1840            if (store.isDefault(newKey))
1841                store.setValue(newKey, store.getString(oldKey));
1842            store.setToDefault(oldKey);
1843            return true;
1844        }
1845        return false;
1846    }
1847    
1848    /**
1849     * Sets the default value and fires a property
1850     * change event if necessary.
1851     *
1852     * @param store the preference store
1853     * @param key the preference key
1854     * @param newValue the new value
1855     * @since 3.3
1856     */

1857    private static void setDefaultAndFireEvent(IPreferenceStore store, String JavaDoc key, RGB newValue) {
1858        RGB oldValue= null;
1859        if (store.isDefault(key))
1860            oldValue= PreferenceConverter.getDefaultColor(store, key);
1861        
1862        PreferenceConverter.setDefault(store, key, newValue);
1863        
1864        if (oldValue != null && !oldValue.equals(newValue))
1865            store.firePropertyChangeEvent(key, oldValue, newValue);
1866    }
1867
1868    /**
1869     * Do not instantiate
1870     */

1871    private SemanticHighlightings() {
1872    }
1873}
1874
Popular Tags