List of usage examples for org.eclipse.jdt.internal.compiler.ast TypeDeclaration printHeader
public StringBuffer printHeader(int indent, StringBuffer output)
From source file:com.google.gwt.dev.jjs.impl.GwtAstBuilder.java
License:Apache License
private void createMembers(TypeDeclaration x) { SourceTypeBinding binding = x.binding; JDeclaredType type = (JDeclaredType) typeMap.get(binding); SourceInfo info = type.getSourceInfo(); try {// ww w .ja va 2 s . c o m /** * 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_NAME, type, JPrimitiveType.VOID, false, true, true, AccessModifier.PRIVATE); if (type instanceof JClassType) { assert type.getMethods().size() == 1; createSyntheticMethod(info, INIT_NAME, type, JPrimitiveType.VOID, false, false, true, AccessModifier.PRIVATE); // Add a getClass() implementation for all non-Object, non-String classes. if (isSyntheticGetClassNeeded(x, type)) { assert type.getMethods().size() == 2; createSyntheticMethod(info, "getClass", type, javaLangClass, false, false, false, AccessModifier.PUBLIC); } } 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; createSyntheticMethodFromBinding(info, valueOfBinding, new String[] { "name" }); } { assert type.getMethods().size() == 4; MethodBinding valuesBinding = binding.getExactMethod(VALUES, NO_TYPES, curCud.scope); assert valuesBinding != null; createSyntheticMethodFromBinding(info, valuesBinding, null); } } if (x.fields != null) { for (FieldDeclaration field : x.fields) { createField(field); } } if (x.methods != null) { for (AbstractMethodDeclaration method : x.methods) { createMethod(method); } } if (x.memberTypes != null) { for (TypeDeclaration memberType : x.memberTypes) { createMembers(memberType); } } } catch (Throwable e) { InternalCompilerException ice = translateException(null, e); StringBuffer sb = new StringBuffer(); x.printHeader(0, sb); ice.addNode(x.getClass().getName(), sb.toString(), type.getSourceInfo()); throw ice; } }
From source file:com.google.gwt.dev.jjs.impl.GwtAstBuilder.java
License:Apache License
private void createTypes(TypeDeclaration x) { SourceInfo info = makeSourceInfo(x); try {/*from w ww . java 2 s . c om*/ SourceTypeBinding binding = x.binding; String name; if (binding instanceof LocalTypeBinding) { char[] localName = binding.constantPoolName(); name = new String(localName).replace('/', '.'); } else { name = JdtUtil.asDottedString(binding.compoundName); } name = intern(name); JDeclaredType type; String jsPrototype = JsInteropUtil.maybeGetJsTypePrototype(x); JsInteropType interopType = JsInteropUtil.maybeGetJsInteropType(x, jsPrototype); if (binding.isClass()) { type = new JClassType(info, name, binding.isAbstract(), binding.isFinal(), interopType); JsInteropUtil.maybeSetJsPrototypeFlag(x, (JClassType) type); } else if (binding.isInterface() || binding.isAnnotationType()) { type = new JInterfaceType(info, name, interopType, jsPrototype); } else if (binding.isEnum()) { if (binding.isAnonymousType()) { // Don't model an enum subclass as a JEnumType. type = new JClassType(info, name, false, true, interopType); } else { type = new JEnumType(info, name, binding.isAbstract(), interopType); } } else { throw new InternalCompilerException("ReferenceBinding is not a class, interface, or enum."); } typeMap.setSourceType(binding, type); newTypes.add(type); if (x.memberTypes != null) { for (TypeDeclaration memberType : x.memberTypes) { createTypes(memberType); } } } catch (Throwable e) { InternalCompilerException ice = translateException(null, e); StringBuffer sb = new StringBuffer(); x.printHeader(0, sb); ice.addNode(x.getClass().getName(), sb.toString(), info); throw ice; } }
From source file:com.google.gwt.dev.jjs.impl.GwtAstBuilder.java
License:Apache License
private void resolveTypeRefs(TypeDeclaration x) { SourceTypeBinding binding = x.binding; JDeclaredType type = (JDeclaredType) typeMap.get(binding); try {// w w w .ja v a2 s . com ReferenceBinding superClassBinding = binding.superclass(); if (type instanceof JClassType && superClassBinding != null) { assert (binding.superclass().isClass() || binding.superclass().isEnum()); JClassType superClass = (JClassType) typeMap.get(superClassBinding); ((JClassType) type).setSuperClass(superClass); } ReferenceBinding[] superInterfaces = binding.superInterfaces(); for (ReferenceBinding superInterfaceBinding : superInterfaces) { assert (superInterfaceBinding.isInterface()); JInterfaceType superInterface = (JInterfaceType) typeMap.get(superInterfaceBinding); type.addImplements(superInterface); } ReferenceBinding enclosingBinding = binding.enclosingType(); if (enclosingBinding != null) { type.setEnclosingType((JDeclaredType) typeMap.get(enclosingBinding)); } if (x.memberTypes != null) { for (TypeDeclaration memberType : x.memberTypes) { resolveTypeRefs(memberType); } } } catch (Throwable e) { InternalCompilerException ice = translateException(null, e); StringBuffer sb = new StringBuffer(); x.printHeader(0, sb); ice.addNode(x.getClass().getName(), sb.toString(), type.getSourceInfo()); throw ice; } }