Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9d0af95da31c5ff34231dc3944aba4cd32ce063c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*******************************************************************************
 * Copyright (c) 2000, 2016 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * IBM - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.core.model;

import org.eclipse.cdt.internal.core.model.IConstants;

/**
 * Utility class for decoding modifier flags in C elements.
 * 
 * @noinstantiate This class is not intended to be instantiated by clients.
 */
public final class Flags {
	/**
	 * Not instantiable.
	 */
	private Flags() {}

	/**
	 * Returns whether the given integer includes the <code>abstract</code> modifier.
	 *
	 * @param flags the flags
	 * @return <code>true</code> if the <code>abstract</code> modifier is included
	 */
	public static boolean isAbstract(int flags) {
		return (flags & IConstants.AccAbstract) != 0;
	}

	/**
	 *
	 * Return whether the give integer include the keyword <code>export</code> modifier.
	 * @param flags the flags
	 * @return <code>true</code> if the element is <code>export</code>
	 */
	public static boolean isExport(int flags) {
		return (flags & IConstants.AccExport) != 0;
	}

	/**
	 * Returns whether the given integer includes the <code>inline</code> modifier.
	 *
	 * @param flags the flags
	 * @return <code>true</code> if the <code>inline</code> modifier is included
	 */
	public static boolean isInline(int flags) {
		return (flags & IConstants.AccInline) != 0;
	}

	/**
	 * Returns whether the given integer includes the <code>explicit</code> modifier.
	 *
	 * @param flags the flags
	 * @return <code>true</code> if <code>explicit</code> modifier is included
	 */
	public static boolean isExplicit(int flags) {
		return (flags & IConstants.AccExplicit) != 0;
	}

	/**
	 * Returns whether the given integer includes the <code>private</code> modifier.
	 *
	 * @param flags the flags
	 * @return <code>true</code> if the <code>private</code> modifier is included
	 */
	public static boolean isPrivate(int flags) {
		return (flags & IConstants.AccPrivate) != 0;
	}

	/**
	 * Returns whether the given integer includes the <code>protected</code> modifier.
	 *
	 * @param flags the flags
	 * @return <code>true</code> if the <code>protected</code> modifier is included
	 */
	public static boolean isProtected(int flags) {
		return (flags & IConstants.AccProtected) != 0;
	}

	/**
	 * Returns whether the given integer includes the <code>public</code> modifier.
	 *
	 * @param flags the flags
	 * @return <code>true</code> if the <code>public</code> modifier is included
	 */
	public static boolean isPublic(int flags) {
		return (flags & IConstants.AccPublic) != 0;
	}

	/**
	 * Returns whether the given integer includes the <code>static</code> modifier.
	 *
	 * @param flags the flags
	 * @return <code>true</code> if the <code>static</code> modifier is included
	 */
	public static boolean isStatic(int flags) {
		return (flags & IConstants.AccStatic) != 0;
	}

	/**
	 * Returns whether the given integer includes the <code>extern</code> modifier.
	 *
	 * @param flags the flags
	 * @return <code>true</code> if the <code>extern</code> modifier is included
	 */
	public static boolean isExtern(int flags) {
		return (flags & IConstants.AccExtern) != 0;
	}
	/**
	 * Returns whether the given integer includes the <code>mutable</code> modifier.
	 *
	 * @param flags the flags
	 * @return <code>true</code> if the <code>mutable</code> modifier is included
	 */
	public static boolean isMutable(int flags) {
		return (flags & IConstants.AccMutable) != 0;
	}

	/**
	 * Returns whether the given integer includes the indication that the 
	 * element is a register storage specifier.
	 *
	 * @param flags the flags
	 * @return <code>true</code> if the element is marked register storage specifier
	 */
	public static boolean isRegister(int flags) {
		return (flags & IConstants.AccRegister) != 0;
	}
	/**
	 * Returns whether the given integer includes the <code>virtual</code> modifier.
	 *
	 * @param flags the flags
	 * @return <code>true</code> if the <code>virtual</code> modifier is included
	 */
	public static boolean isVirtual(int flags) {
		return (flags &  IConstants.AccVirtual) != 0;
	}

	/**
	 * Returns whether the given integer includes the <code>volatile</code> modifier.
	 *
	 * @param flags the flags
	 * @return <code>true</code> if the <code>volatile</code> modifier is included
	 */
	public static boolean isVolatile(int flags) {
		return (flags & IConstants.AccVolatile) != 0;
	}

	/**
	 * Returns a standard string describing the given modifier flags.
	 * Only modifier flags are included in the output; the deprecated and
	 * synthetic flags are ignored if set.
	 * <p>
	 * Examples results:
	 * <pre>
	 *	  <code>"public static"</code>
	 *	  <code>"private"</code>
	 * </pre>
	 * </p>
	 *
	 * @param flags the flags
	 * @return the standard string representation of the given flags
	 */
	public static String toString(int flags) {
		StringBuilder sb = new StringBuilder();

		if (isPublic(flags))	sb.append("public "); //$NON-NLS-1$
		if (isProtected(flags)) sb.append("protected "); //$NON-NLS-1$
		if (isPrivate(flags))	sb.append("private "); //$NON-NLS-1$
		if (isStatic(flags)) sb.append("static "); //$NON-NLS-1$
		if (isAbstract(flags)) sb.append("abstract "); //$NON-NLS-1$
		if (isVirtual(flags)) sb.append("virtual "); //$NON-NLS-1$
		if (isInline(flags)) sb.append("inline "); //$NON-NLS-1$
		if (isExtern(flags)) sb.append("extern "); //$NON-NLS-1$
		if (isExport(flags)) sb.append("export "); //$NON-NLS-1$
		if (isVolatile(flags)) sb.append("volatile "); //$NON-NLS-1$
		if (isExplicit(flags)) sb.append("explicit "); //$NON-NLS-1$

		int len = sb.length();
		if (len == 0) return ""; //$NON-NLS-1$
		sb.setLength(len-1);
		return sb.toString();
	}
}

Back to the top