public TType create(ITypeBinding binding) { if (binding.isPrimitive()) { return createPrimitiveType(binding); } else if (binding.isArray()) { return createArrayType(binding); } if ("null".equals(binding.getName())) // $NON-NLS-1$ return NULL; return createStandardType(binding); }
private ArrayType createArrayType(ITypeBinding binding) { int index = binding.getDimensions() - 1; TType elementType = create(binding.getElementType()); Map /*<TType, ArrayType>*/ arrayTypes = getArrayTypesMap(index); ArrayType result = (ArrayType) arrayTypes.get(elementType); if (result != null) return result; result = new ArrayType(this); arrayTypes.put(elementType, result); result.initialize(binding, elementType); return result; }
private CaptureType createCaptureType(ITypeBinding binding) { IJavaScriptProject javaProject = binding.getDeclaringClass().getJavaElement().getJavaScriptProject(); String bindingKey = binding.getKey(); ProjectKeyPair pair = new ProjectKeyPair(javaProject, bindingKey); CaptureType result = (CaptureType) fCaptureTypes.get(pair); if (result != null) return result; result = new CaptureType(this); fCaptureTypes.put(pair, result); result.initialize(binding, javaProject); return result; }
private boolean matches(ITypeBinding exception) { if (exception == null) return false; while (exception != null) { if (Bindings.equals(fException, exception)) return true; exception = exception.getSuperclass(); } return false; }
private StandardType createStandardType(ITypeBinding binding) { IJavaScriptElement javaElement = binding.getJavaElement(); StandardType result = (StandardType) fStandardTypes.get(javaElement); if (result != null) return result; result = new StandardType(this); fStandardTypes.put(javaElement, result); result.initialize(binding, (IType) javaElement); if (OBJECT_TYPE == null && result.isJavaLangObject()) OBJECT_TYPE = result; return result; }
private RawType createRawType(ITypeBinding binding) { IJavaScriptElement javaElement = binding.getJavaElement(); RawType result = (RawType) fRawTypes.get(javaElement); if (result != null) return result; result = new RawType(this); fRawTypes.put(javaElement, result); result.initialize(binding, (IType) javaElement); cacheSubType(result.getSuperclass(), result); cacheSubTypes(result.getInterfaces(), result); return result; }
private TType createPrimitiveType(ITypeBinding binding) { String name = binding.getName(); String[] names = PrimitiveType.NAMES; for (int i = 0; i < names.length; i++) { if (name.equals(names[i])) { return PRIMITIVE_TYPES[i]; } } Assert.isTrue(false, "Primitive type " + name + "unkown"); // $NON-NLS-1$//$NON-NLS-2$ return null; }
/** * Adds the necessary imports for an AST node to the specified compilation unit. * * @param rewrite the compilation unit rewrite whose compilation unit's imports should be updated * @param node the AST node specifying the element for which imports should be added * @param typeImports the map of name nodes to strings (element type: Map <Name, String>). * @param staticImports the map of name nodes to strings (element type: Map <Name, String>). * @param excludeBindings the set of bindings to exclude (element type: Set <IBinding>). * @param declarations <code>true</code> if method declarations are treated as abstract, <code> * false</code> otherwise */ public static void addImports( final CompilationUnitRewrite rewrite, final ASTNode node, final Map typeImports, final Map staticImports, final Collection excludeBindings, final boolean declarations) { Assert.isNotNull(rewrite); Assert.isNotNull(node); Assert.isNotNull(typeImports); Assert.isNotNull(staticImports); final Set types = new HashSet(); final Set members = new HashSet(); final ImportReferencesCollector collector = new ImportReferencesCollector( rewrite.getCu().getJavaScriptProject(), null, types, members) { public final boolean visit(final Block block) { Assert.isNotNull(block); if (declarations && block.getParent() instanceof FunctionDeclaration) return false; return super.visit(block); } }; node.accept(collector); final ImportRewrite rewriter = rewrite.getImportRewrite(); final ImportRemover remover = rewrite.getImportRemover(); Name name = null; IBinding binding = null; for (final Iterator iterator = types.iterator(); iterator.hasNext(); ) { name = (Name) iterator.next(); binding = name.resolveBinding(); if (binding instanceof ITypeBinding) { final ITypeBinding type = (ITypeBinding) binding; if (excludeBindings == null || !excludeBindings.contains(type)) { typeImports.put(name, rewriter.addImport(type)); remover.registerAddedImport(type.getQualifiedName()); } } } for (final Iterator iterator = members.iterator(); iterator.hasNext(); ) { name = (Name) iterator.next(); binding = name.resolveBinding(); if (binding instanceof IVariableBinding) { final IVariableBinding variable = (IVariableBinding) binding; final ITypeBinding declaring = variable.getDeclaringClass(); if (declaring != null && (excludeBindings == null || !excludeBindings.contains(variable))) { staticImports.put(name, rewriter.addStaticImport(variable)); remover.registerAddedStaticImport(declaring.getQualifiedName(), variable.getName(), true); } } else if (binding instanceof IFunctionBinding) { final IFunctionBinding method = (IFunctionBinding) binding; final ITypeBinding declaring = method.getDeclaringClass(); if (declaring != null && (excludeBindings == null || !excludeBindings.contains(method))) { staticImports.put(name, rewriter.addStaticImport(method)); remover.registerAddedStaticImport(declaring.getQualifiedName(), method.getName(), false); } } } }
private static boolean isStringExpression(Expression expression) { ITypeBinding binding = expression.resolveTypeBinding(); return binding.getQualifiedName().equals("String"); // $NON-NLS-1$ }