public static ITypeBinding[] createTypeBindings(TType[] types, IJavaScriptProject project) { final Map mapping = new HashMap(); List keys = new ArrayList(); for (int i = 0; i < types.length; i++) { TType type = types[i]; String bindingKey = type.getBindingKey(); mapping.put(bindingKey, type); keys.add(bindingKey); } ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setProject(project); parser.setResolveBindings(true); parser.createASTs( new IJavaScriptUnit[0], (String[]) keys.toArray(new String[keys.size()]), new ASTRequestor() { public void acceptBinding(String bindingKey, IBinding binding) { mapping.put(bindingKey, binding); } }, null); ITypeBinding[] result = new ITypeBinding[types.length]; for (int i = 0; i < types.length; i++) { TType type = types[i]; String bindingKey = type.getBindingKey(); Object value = mapping.get(bindingKey); if (value instanceof ITypeBinding) { result[i] = (ITypeBinding) value; } } return result; }
StandardType createBoxed(PrimitiveType type, IJavaScriptProject focus) { String fullyQualifiedName = BOXED_PRIMITIVE_NAMES[type.getId()]; try { IType javaElementType = focus.findType(fullyQualifiedName); StandardType result = (StandardType) fStandardTypes.get(javaElementType); if (result != null) return result; ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setProject(focus); IBinding[] bindings = parser.createBindings(new IJavaScriptElement[] {javaElementType}, null); return createStandardType((ITypeBinding) bindings[0]); } catch (JavaScriptModelException e) { // fall through } return null; }