001: /*
002: * Copyright 2006 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package com.google.gwt.dev.jdt;
017:
018: import com.google.gwt.core.ext.typeinfo.JClassType;
019: import com.google.gwt.core.ext.typeinfo.JConstructor;
020: import com.google.gwt.core.ext.typeinfo.JField;
021: import com.google.gwt.core.ext.typeinfo.JMethod;
022: import com.google.gwt.core.ext.typeinfo.JPackage;
023: import com.google.gwt.core.ext.typeinfo.JParameter;
024: import com.google.gwt.core.ext.typeinfo.JType;
025:
026: import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
027: import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
028: import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
029:
030: import java.util.ArrayList;
031: import java.util.List;
032:
033: /**
034: * Utility methods and constants.
035: */
036: class Shared {
037: static final int MOD_ABSTRACT = 0x00000001;
038: static final int MOD_FINAL = 0x00000002;
039: static final int MOD_NATIVE = 0x00000004;
040: static final int MOD_PRIVATE = 0x00000008;
041: static final int MOD_PROTECTED = 0x00000010;
042: static final int MOD_PUBLIC = 0x00000020;
043: static final int MOD_STATIC = 0x00000040;
044: static final int MOD_TRANSIENT = 0x00000080;
045: static final int MOD_VOLATILE = 0x00000100;
046: static final JClassType[] NO_JCLASSES = new JClassType[0];
047: static final JConstructor[] NO_JCTORS = new JConstructor[0];
048: static final JField[] NO_JFIELDS = new JField[0];
049: static final JMethod[] NO_JMETHODS = new JMethod[0];
050: static final JPackage[] NO_JPACKAGES = new JPackage[0];
051: static final JParameter[] NO_JPARAMS = new JParameter[0];
052: static final JType[] NO_JTYPES = new JType[0];
053: static final String[][] NO_STRING_ARR_ARR = new String[0][];
054: static final String[] NO_STRINGS = new String[0];
055:
056: public static int bindingToModifierBits(FieldBinding binding) {
057: int bits = 0;
058: bits |= (binding.isPublic() ? MOD_PUBLIC : 0);
059: bits |= (binding.isPrivate() ? MOD_PRIVATE : 0);
060: bits |= (binding.isProtected() ? MOD_PROTECTED : 0);
061: bits |= (binding.isStatic() ? MOD_STATIC : 0);
062: bits |= (binding.isTransient() ? MOD_TRANSIENT : 0);
063: bits |= (binding.isFinal() ? MOD_FINAL : 0);
064: bits |= (binding.isVolatile() ? MOD_VOLATILE : 0);
065: return bits;
066: }
067:
068: public static int bindingToModifierBits(MethodBinding binding) {
069: int bits = 0;
070: bits |= (binding.isPublic() ? MOD_PUBLIC : 0);
071: bits |= (binding.isPrivate() ? MOD_PRIVATE : 0);
072: bits |= (binding.isProtected() ? MOD_PROTECTED : 0);
073: bits |= (binding.isStatic() ? MOD_STATIC : 0);
074: bits |= (binding.isFinal() ? MOD_FINAL : 0);
075: bits |= (binding.isNative() ? MOD_NATIVE : 0);
076: bits |= (binding.isAbstract() ? MOD_ABSTRACT : 0);
077: return bits;
078: }
079:
080: public static int bindingToModifierBits(ReferenceBinding binding) {
081: int bits = 0;
082: bits |= (binding.isPublic() ? MOD_PUBLIC : 0);
083: bits |= (binding.isPrivate() ? MOD_PRIVATE : 0);
084: bits |= (binding.isProtected() ? MOD_PROTECTED : 0);
085: bits |= (binding.isStatic() ? MOD_STATIC : 0);
086: bits |= (binding.isFinal() ? MOD_FINAL : 0);
087: bits |= (binding.isAbstract() ? MOD_ABSTRACT : 0);
088: return bits;
089: }
090:
091: static String[] modifierBitsToNames(int bits) {
092: List strings = new ArrayList();
093:
094: // The order is based on the order in which we want them to appear.
095: //
096: if (0 != (bits & MOD_PUBLIC)) {
097: strings.add("public");
098: }
099:
100: if (0 != (bits & MOD_PRIVATE)) {
101: strings.add("private");
102: }
103:
104: if (0 != (bits & MOD_PROTECTED)) {
105: strings.add("protected");
106: }
107:
108: if (0 != (bits & MOD_STATIC)) {
109: strings.add("static");
110: }
111:
112: if (0 != (bits & MOD_ABSTRACT)) {
113: strings.add("abstract");
114: }
115:
116: if (0 != (bits & MOD_FINAL)) {
117: strings.add("final");
118: }
119:
120: if (0 != (bits & MOD_NATIVE)) {
121: strings.add("native");
122: }
123:
124: if (0 != (bits & MOD_TRANSIENT)) {
125: strings.add("transient");
126: }
127:
128: if (0 != (bits & MOD_VOLATILE)) {
129: strings.add("volatile");
130: }
131:
132: return (String[]) strings.toArray(NO_STRINGS);
133: }
134:
135: }
|