List of usage examples for org.eclipse.jdt.internal.compiler.lookup ArrayBinding elementsType
public TypeBinding elementsType()
From source file:com.google.gwt.dev.jjs.impl.ReferenceMapper.java
License:Apache License
public JType get(TypeBinding binding) { binding = binding.erasure();/*from w ww.jav a 2 s . com*/ String key = JdtUtil.signature(binding); JReferenceType sourceType = sourceTypes.get(key); if (sourceType != null) { assert !sourceType.isExternal(); return sourceType; } JType type = types.get(key); if (type != null) { assert type instanceof JPrimitiveType || type == JNullType.INSTANCE || type.isExternal(); return type; } assert !(binding instanceof BaseTypeBinding); if (binding instanceof ArrayBinding) { ArrayBinding arrayBinding = (ArrayBinding) binding; JArrayType arrayType = new JArrayType(get(arrayBinding.elementsType())); if (arrayType.isExternal()) { types.put(key, arrayType); } else { sourceTypes.put(key, arrayType); } return arrayType; } else { ReferenceBinding refBinding = (ReferenceBinding) binding; JDeclaredType declType = createType(refBinding); try { if (declType instanceof JClassType) { ReferenceBinding superclass = refBinding.superclass(); if (superclass != null && superclass.isValidBinding()) { ((JClassType) declType).setSuperClass((JClassType) get(superclass)); } } ReferenceBinding[] superInterfaces = refBinding.superInterfaces(); if (superInterfaces != null) { for (ReferenceBinding intf : superInterfaces) { if (intf.isValidBinding()) { declType.addImplements((JInterfaceType) get(intf)); } } } } catch (AbortCompilation ignored) { /* * The currently-compiling unit has no errors; however, we're running * into a case where it references something with a bad hierarchy. This * doesn't cause an error in the current unit, but it does mean we run * into a wall here trying to construct the hierarchy. Catch the error * so that compilation can proceed; the error units themselves will * eventually cause the full compile to error out. */ } // Emulate clinit method for super clinit calls. JMethod clinit = new JMethod(SourceOrigin.UNKNOWN, GwtAstBuilder.CLINIT_NAME, declType, JPrimitiveType.VOID, false, true, true, AccessModifier.PRIVATE); clinit.freezeParamTypes(); clinit.setSynthetic(); declType.addMethod(clinit); declType.setExternal(true); types.put(key, declType); return declType; } }
From source file:com.google.gwt.dev.jjs.impl.TypeMap.java
License:Apache License
private JNode internalGet(Binding binding, boolean failOnNull) { JNode cached = crossRefMap.get(binding); if (cached != null) { return cached; } else if (binding instanceof BaseTypeBinding) { BaseTypeBinding baseTypeBinding = (BaseTypeBinding) binding; // see org.eclipse.jdt.internal.compiler.lookup.TypeIds constants switch (baseTypeBinding.id) { case TypeIds.T_JavaLangObject: // here for consistency, should already be cached return program.getTypeJavaLangObject(); case TypeIds.T_char: return program.getTypePrimitiveChar(); case TypeIds.T_byte: return program.getTypePrimitiveByte(); case TypeIds.T_short: return program.getTypePrimitiveShort(); case TypeIds.T_boolean: return program.getTypePrimitiveBoolean(); case TypeIds.T_void: return program.getTypeVoid(); case TypeIds.T_long: return program.getTypePrimitiveLong(); case TypeIds.T_double: return program.getTypePrimitiveDouble(); case TypeIds.T_float: return program.getTypePrimitiveFloat(); case TypeIds.T_int: return program.getTypePrimitiveInt(); case TypeIds.T_JavaLangString: // here for consistency, should already be cached return program.getTypeJavaLangString(); case TypeIds.T_null: return program.getTypeNull(); case TypeIds.T_undefined: default:/*w w w . java 2 s. c om*/ return null; } } else if (binding instanceof ArrayBinding) { ArrayBinding arrayBinding = (ArrayBinding) binding; JType elementType = (JType) get(arrayBinding.elementsType(), failOnNull); if (elementType == null) { return null; } return program.getTypeArray(elementType); } else if (binding instanceof BinaryTypeBinding) { BinaryTypeBinding binaryBinding = (BinaryTypeBinding) binding; String name = BuildTypeMap.dotify(binaryBinding.compoundName); // There may be many BinaryTypeBindings for a single binary type JDeclaredType type = externalTypesByName.get(name); if (type != null) { put(binding, type); } return type; } else if (binding instanceof MethodBinding) { MethodBinding b = (MethodBinding) binding; JMethod cachedMethod = (JMethod) crossRefMap.get(b); if (cachedMethod == null) { JDeclaredType type = (JDeclaredType) get(b.declaringClass, failOnNull); if (type == null) { return type; } cachedMethod = getMethodForBinding(type, b); if (cachedMethod != null) { put(b, cachedMethod); } } else { // Happens sometimes when looking up the type to resolve the binding // causes us to also resolve the binding. } return cachedMethod; } else if (binding instanceof FieldBinding) { FieldBinding b = (FieldBinding) binding; JField cachedField = (JField) crossRefMap.get(b); if (cachedField == null) { JDeclaredType type = (JDeclaredType) get(b.declaringClass, failOnNull); if (type == null) { return null; } cachedField = getFieldForBinding(type, b); if (cachedField != null) { put(b, cachedField); } } else { // Happens sometimes when looking up the type to resolve the binding // causes us to also resolve the binding. } return cachedField; } return null; }