enclosingType.addField(field);
typeMap.setField(binding, field);
}
private void createMembers(TypeDeclaration x) {
SourceTypeBinding binding = x.binding;
JDeclaredType type = (JDeclaredType) typeMap.get(binding);
SourceInfo info = type.getSourceInfo();
try {
/**
* We emulate static initializers and instance initializers as methods. As
* in other cases, this gives us: simpler AST, easier to optimize, more
* like output JavaScript. Clinit is always in slot 0, init (if it exists)
* is always in slot 1.
*/
assert type.getMethods().size() == 0;
createSyntheticMethod(info, "$clinit", type, JPrimitiveType.VOID, false, true, true, true);
if (type instanceof JClassType) {
assert type.getMethods().size() == 1;
createSyntheticMethod(info, "$init", type, JPrimitiveType.VOID, false, false, true, true);
// Add a getClass() implementation for all non-Object classes.
if (type != javaLangObject && !JSORestrictionsChecker.isJsoSubclass(binding)) {
assert type.getMethods().size() == 2;
createSyntheticMethod(info, "getClass", type, javaLangClass, false, false, false, false);
}
}
if (type instanceof JEnumType) {
{
assert type.getMethods().size() == 3;
MethodBinding valueOfBinding =
binding.getExactMethod(VALUE_OF, new TypeBinding[]{x.scope.getJavaLangString()},
curCud.scope);
assert valueOfBinding != null;
createSynthicMethodFromBinding(info, valueOfBinding, new String[]{"name"});
}
{
assert type.getMethods().size() == 4;
MethodBinding valuesBinding = binding.getExactMethod(VALUES, NO_TYPES, curCud.scope);
assert valuesBinding != null;
createSynthicMethodFromBinding(info, valuesBinding, null);
}
}