KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > codeassist > impl > AssistOptions


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 package org.eclipse.jdt.internal.codeassist.impl;
12
13 import java.util.Map JavaDoc;
14
15 import org.eclipse.jdt.core.compiler.CharOperation;
16
17 public class AssistOptions {
18     /**
19      * Option IDs
20      */

21     public static final String JavaDoc OPTION_PerformVisibilityCheck =
22         "org.eclipse.jdt.core.codeComplete.visibilityCheck"; //$NON-NLS-1$
23
public static final String JavaDoc OPTION_PerformDeprecationCheck =
24         "org.eclipse.jdt.core.codeComplete.deprecationCheck"; //$NON-NLS-1$
25
public static final String JavaDoc OPTION_ForceImplicitQualification =
26         "org.eclipse.jdt.core.codeComplete.forceImplicitQualification"; //$NON-NLS-1$
27
public static final String JavaDoc OPTION_FieldPrefixes =
28         "org.eclipse.jdt.core.codeComplete.fieldPrefixes"; //$NON-NLS-1$
29
public static final String JavaDoc OPTION_StaticFieldPrefixes =
30         "org.eclipse.jdt.core.codeComplete.staticFieldPrefixes"; //$NON-NLS-1$
31
public static final String JavaDoc OPTION_LocalPrefixes =
32         "org.eclipse.jdt.core.codeComplete.localPrefixes"; //$NON-NLS-1$
33
public static final String JavaDoc OPTION_ArgumentPrefixes =
34         "org.eclipse.jdt.core.codeComplete.argumentPrefixes"; //$NON-NLS-1$
35
public static final String JavaDoc OPTION_FieldSuffixes =
36         "org.eclipse.jdt.core.codeComplete.fieldSuffixes"; //$NON-NLS-1$
37
public static final String JavaDoc OPTION_StaticFieldSuffixes =
38         "org.eclipse.jdt.core.codeComplete.staticFieldSuffixes"; //$NON-NLS-1$
39
public static final String JavaDoc OPTION_LocalSuffixes =
40         "org.eclipse.jdt.core.codeComplete.localSuffixes"; //$NON-NLS-1$
41
public static final String JavaDoc OPTION_ArgumentSuffixes =
42         "org.eclipse.jdt.core.codeComplete.argumentSuffixes"; //$NON-NLS-1$
43
public static final String JavaDoc OPTION_PerformForbiddenReferenceCheck =
44         "org.eclipse.jdt.core.codeComplete.forbiddenReferenceCheck"; //$NON-NLS-1$
45
public static final String JavaDoc OPTION_PerformDiscouragedReferenceCheck =
46         "org.eclipse.jdt.core.codeComplete.discouragedReferenceCheck"; //$NON-NLS-1$
47
public static final String JavaDoc OPTION_CamelCaseMatch =
48         "org.eclipse.jdt.core.codeComplete.camelCaseMatch"; //$NON-NLS-1$
49
public static final String JavaDoc OPTION_SuggestStaticImports =
50         "org.eclipse.jdt.core.codeComplete.suggestStaticImports"; //$NON-NLS-1$
51

52     public static final String JavaDoc ENABLED = "enabled"; //$NON-NLS-1$
53
public static final String JavaDoc DISABLED = "disabled"; //$NON-NLS-1$
54

55     public boolean checkVisibility = false;
56     public boolean checkDeprecation = false;
57     public boolean checkForbiddenReference = false;
58     public boolean checkDiscouragedReference = false;
59     public boolean forceImplicitQualification = false;
60     public boolean camelCaseMatch = true;
61     public boolean suggestStaticImport = true;
62     public char[][] fieldPrefixes = null;
63     public char[][] staticFieldPrefixes = null;
64     public char[][] localPrefixes = null;
65     public char[][] argumentPrefixes = null;
66     public char[][] fieldSuffixes = null;
67     public char[][] staticFieldSuffixes = null;
68     public char[][] localSuffixes = null;
69     public char[][] argumentSuffixes = null;
70
71     /**
72      * Initializing the assist options with default settings
73      */

74     public AssistOptions() {
75         // Initializing the assist options with default settings
76
}
77
78     /**
79      * Initializing the assist options with external settings
80      */

81     public AssistOptions(Map JavaDoc settings) {
82         if (settings == null)
83             return;
84
85         set(settings);
86     }
87     public void set(Map JavaDoc optionsMap) {
88
89         Object JavaDoc optionValue;
90         if ((optionValue = optionsMap.get(OPTION_PerformVisibilityCheck)) != null) {
91             if (ENABLED.equals(optionValue)) {
92                 this.checkVisibility = true;
93             } else if (DISABLED.equals(optionValue)) {
94                 this.checkVisibility = false;
95             }
96         }
97         if ((optionValue = optionsMap.get(OPTION_ForceImplicitQualification)) != null) {
98             if (ENABLED.equals(optionValue)) {
99                 this.forceImplicitQualification = true;
100             } else if (DISABLED.equals(optionValue)) {
101                 this.forceImplicitQualification = false;
102             }
103         }
104         if ((optionValue = optionsMap.get(OPTION_FieldPrefixes)) != null) {
105             if (optionValue instanceof String JavaDoc) {
106                 String JavaDoc stringValue = (String JavaDoc) optionValue;
107                 if (stringValue.length() > 0){
108                     this.fieldPrefixes = this.splitAndTrimOn(',', stringValue.toCharArray());
109                 } else {
110                     this.fieldPrefixes = null;
111                 }
112             }
113         }
114         if ((optionValue = optionsMap.get(OPTION_StaticFieldPrefixes)) != null) {
115             if (optionValue instanceof String JavaDoc) {
116                 String JavaDoc stringValue = (String JavaDoc) optionValue;
117                 if (stringValue.length() > 0){
118                     this.staticFieldPrefixes = this.splitAndTrimOn(',', stringValue.toCharArray());
119                 } else {
120                     this.staticFieldPrefixes = null;
121                 }
122             }
123         }
124         if ((optionValue = optionsMap.get(OPTION_LocalPrefixes)) != null) {
125             if (optionValue instanceof String JavaDoc) {
126                 String JavaDoc stringValue = (String JavaDoc) optionValue;
127                 if (stringValue.length() > 0){
128                     this.localPrefixes = this.splitAndTrimOn(',', stringValue.toCharArray());
129                 } else {
130                     this.localPrefixes = null;
131                 }
132             }
133         }
134         if ((optionValue = optionsMap.get(OPTION_ArgumentPrefixes)) != null) {
135             if (optionValue instanceof String JavaDoc) {
136                 String JavaDoc stringValue = (String JavaDoc) optionValue;
137                 if (stringValue.length() > 0){
138                     this.argumentPrefixes = this.splitAndTrimOn(',', stringValue.toCharArray());
139                 } else {
140                     this.argumentPrefixes = null;
141                 }
142             }
143         }
144         if ((optionValue = optionsMap.get(OPTION_FieldSuffixes)) != null) {
145             if (optionValue instanceof String JavaDoc) {
146                 String JavaDoc stringValue = (String JavaDoc) optionValue;
147                 if (stringValue.length() > 0){
148                     this.fieldSuffixes = this.splitAndTrimOn(',', stringValue.toCharArray());
149                 } else {
150                     this.fieldSuffixes = null;
151                 }
152             }
153         }
154         if ((optionValue = optionsMap.get(OPTION_StaticFieldSuffixes)) != null) {
155             if (optionValue instanceof String JavaDoc) {
156                 String JavaDoc stringValue = (String JavaDoc) optionValue;
157                 if (stringValue.length() > 0){
158                     this.staticFieldSuffixes = this.splitAndTrimOn(',', stringValue.toCharArray());
159                 } else {
160                     this.staticFieldSuffixes = null;
161                 }
162             }
163         }
164         if ((optionValue = optionsMap.get(OPTION_LocalSuffixes)) != null) {
165             if (optionValue instanceof String JavaDoc) {
166                 String JavaDoc stringValue = (String JavaDoc) optionValue;
167                 if (stringValue.length() > 0){
168                     this.localSuffixes = this.splitAndTrimOn(',', stringValue.toCharArray());
169                 } else {
170                     this.localSuffixes = null;
171                 }
172             }
173         }
174         if ((optionValue = optionsMap.get(OPTION_ArgumentSuffixes)) != null) {
175             if (optionValue instanceof String JavaDoc) {
176                 String JavaDoc stringValue = (String JavaDoc) optionValue;
177                 if (stringValue.length() > 0){
178                     this.argumentSuffixes = this.splitAndTrimOn(',', stringValue.toCharArray());
179                 } else {
180                     this.argumentSuffixes = null;
181                 }
182             }
183         }
184         if ((optionValue = optionsMap.get(OPTION_PerformForbiddenReferenceCheck)) != null) {
185             if (ENABLED.equals(optionValue)) {
186                 this.checkForbiddenReference = true;
187             } else if (DISABLED.equals(optionValue)) {
188                 this.checkForbiddenReference = false;
189             }
190         }
191         if ((optionValue = optionsMap.get(OPTION_PerformDiscouragedReferenceCheck)) != null) {
192             if (ENABLED.equals(optionValue)) {
193                 this.checkDiscouragedReference = true;
194             } else if (DISABLED.equals(optionValue)) {
195                 this.checkDiscouragedReference = false;
196             }
197         }
198         if ((optionValue = optionsMap.get(OPTION_CamelCaseMatch)) != null) {
199             if (ENABLED.equals(optionValue)) {
200                 this.camelCaseMatch = true;
201             } else if (DISABLED.equals(optionValue)) {
202                 this.camelCaseMatch = false;
203             }
204         }
205         if ((optionValue = optionsMap.get(OPTION_PerformDeprecationCheck)) != null) {
206             if (ENABLED.equals(optionValue)) {
207                 this.checkDeprecation = true;
208             } else if (DISABLED.equals(optionValue)) {
209                 this.checkDeprecation = false;
210             }
211         }
212         if ((optionValue = optionsMap.get(OPTION_SuggestStaticImports)) != null) {
213             if (ENABLED.equals(optionValue)) {
214                 this.suggestStaticImport = true;
215             } else if (DISABLED.equals(optionValue)) {
216                 this.suggestStaticImport = false;
217             }
218         }
219     }
220     
221     private char[][] splitAndTrimOn(char divider, char[] arrayToSplit) {
222         char[][] result = CharOperation.splitAndTrimOn(',', arrayToSplit);
223         
224         int length = result.length;
225         
226         int resultCount = 0;
227         for (int i = 0; i < length; i++) {
228             if(result[i].length != 0) {
229                 result[resultCount++] = result[i];
230             }
231         }
232         if(resultCount != length) {
233             System.arraycopy(result, 0, result = new char[resultCount][], 0, resultCount);
234         }
235         return result;
236     }
237 }
238
Popular Tags