~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to java/editor/src/org/netbeans/modules/java/editor/semantic/ColoringAttributes.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
package org.netbeans.modules.java.editor.semantic;
 
42
 
 
43
import java.util.Collection;
 
44
import java.util.EnumSet;
 
45
import java.util.Iterator;
 
46
import java.util.Set;
 
47
 
 
48
/**
 
49
 *
 
50
 * @author Jan Lahoda
 
51
 */
 
52
public enum ColoringAttributes {
 
53
 
 
54
    UNUSED,
 
55
 
 
56
    ABSTRACT,
 
57
 
 
58
    FIELD,
 
59
    LOCAL_VARIABLE,
 
60
    PARAMETER,
 
61
    METHOD,
 
62
    CONSTRUCTOR,
 
63
    CLASS,
 
64
    INTERFACE,
 
65
    ANNOTATION_TYPE,
 
66
    ENUM,
 
67
    DEPRECATED,
 
68
    STATIC,
 
69
 
 
70
    DECLARATION,
 
71
    
 
72
    PRIVATE,
 
73
    PACKAGE_PRIVATE,
 
74
    PROTECTED,
 
75
    PUBLIC,
 
76
 
 
77
    TYPE_PARAMETER_DECLARATION,
 
78
    TYPE_PARAMETER_USE,
 
79
 
 
80
    UNDEFINED,
 
81
 
 
82
    MARK_OCCURRENCES;
 
83
    
 
84
    public static Coloring empty() {
 
85
        return new Coloring();
 
86
    }
 
87
    
 
88
    public static Coloring add(Coloring c, ColoringAttributes a) {
 
89
        Coloring ci = new Coloring();
 
90
        
 
91
        ci.value = c.value | (1 << a.ordinal());
 
92
        
 
93
        return ci;
 
94
    }
 
95
 
 
96
    public static final class Coloring implements Collection<ColoringAttributes> {
 
97
 
 
98
        private int value;
 
99
        
 
100
        private Coloring() {}
 
101
        
 
102
        public int size() {
 
103
            return Integer.bitCount(value);
 
104
        }
 
105
 
 
106
        public boolean isEmpty() {
 
107
            return value == 0;
 
108
        }
 
109
 
 
110
        public boolean contains(Object o) {
 
111
            if (o instanceof ColoringAttributes) {
 
112
                return (value & (1 << ((ColoringAttributes) o).ordinal())) !=0;
 
113
            } else {
 
114
                return false;
 
115
            }
 
116
        }
 
117
 
 
118
        public Iterator<ColoringAttributes> iterator() {
 
119
            Set<ColoringAttributes> s = EnumSet.noneOf(ColoringAttributes.class);
 
120
            for (ColoringAttributes c : ColoringAttributes.values()) {
 
121
                if (contains(c))
 
122
                    s.add(c);
 
123
            }
 
124
            
 
125
            return s.iterator();
 
126
        }
 
127
 
 
128
        public Object[] toArray() {
 
129
            throw new UnsupportedOperationException("Not supported yet.");
 
130
        }
 
131
 
 
132
        public <T> T[] toArray(T[] a) {
 
133
            throw new UnsupportedOperationException("Not supported yet.");
 
134
        }
 
135
 
 
136
        public boolean add(ColoringAttributes o) {
 
137
            throw new UnsupportedOperationException("Not supported yet.");
 
138
        }
 
139
 
 
140
        public boolean remove(Object o) {
 
141
            throw new UnsupportedOperationException("Not supported yet.");
 
142
        }
 
143
 
 
144
        public boolean containsAll(Collection<?> c) {
 
145
            for (Object o : c) {
 
146
                if (!contains(o))
 
147
                    return false;
 
148
            }
 
149
            
 
150
            return true;
 
151
        }
 
152
 
 
153
        public boolean addAll(Collection<? extends ColoringAttributes> c) {
 
154
            throw new UnsupportedOperationException("Not supported yet.");
 
155
        }
 
156
 
 
157
        public boolean removeAll(Collection<?> c) {
 
158
            throw new UnsupportedOperationException("Not supported yet.");
 
159
        }
 
160
 
 
161
        public boolean retainAll(Collection<?> c) {
 
162
            throw new UnsupportedOperationException("Not supported yet.");
 
163
        }
 
164
 
 
165
        public void clear() {
 
166
            throw new UnsupportedOperationException("Not supported yet.");
 
167
        }
 
168
 
 
169
        @Override
 
170
        public int hashCode() {
 
171
            return value;
 
172
        }
 
173
 
 
174
        @Override
 
175
        public boolean equals(Object obj) {
 
176
            if (obj instanceof Coloring) {
 
177
                //XXX:
 
178
                return ((Coloring) obj).value == value;
 
179
            }
 
180
            
 
181
            return false;
 
182
        }
 
183
        
 
184
        
 
185
    }
 
186
}