// Função auxiliar para copiar o tipo da variável // considerando que um tipo nao pode pertencer a outra AST private Type getType(ITypeBinding typeBinding, AST newAST) { if (typeBinding.isPrimitive()) { return newAST.newPrimitiveType(PrimitiveType.toCode(typeBinding.getName())); } else if (typeBinding.isArray()) { return newAST.newArrayType( this.getType(typeBinding.getElementType(), newAST), typeBinding.getDimensions()); } else if (typeBinding.isParameterizedType()) { ParameterizedType pt = newAST.newParameterizedType(this.getType(typeBinding.getTypeDeclaration(), newAST)); for (ITypeBinding itb : typeBinding.getTypeArguments()) { pt.typeArguments().add(this.getType(itb, newAST)); } return pt; } else if (typeBinding.isWildcardType()) { WildcardType wt = newAST.newWildcardType(); wt.setBound( typeBinding.getBound() == null ? null : this.getType(typeBinding.getBound(), newAST), typeBinding.isUpperbound()); return wt; } else { try { return newAST.newSimpleType(newAST.newName(typeBinding.getQualifiedName())); } catch (Exception e) { return newAST.newSimpleType(newAST.newName(typeBinding.getName())); } } }
/** Determines if a type can access fields and methods from an outer class. */ public static boolean hasOuterContext(ITypeBinding type) { if (type.getDeclaringClass() == null) { return false; } // Local types can't be declared static, but if the declaring method is // static then the local type is effectively static. IMethodBinding declaringMethod = type.getTypeDeclaration().getDeclaringMethod(); if (declaringMethod != null) { return !BindingUtil.isStatic(declaringMethod); } return !BindingUtil.isStatic(type); }
private static boolean isRawTypeReference(ASTNode node) { if (!(node instanceof SimpleType)) return false; ITypeBinding typeBinding = ((SimpleType) node).resolveBinding(); if (typeBinding == null) return false; ITypeBinding binding = typeBinding.getTypeDeclaration(); if (binding == null) return false; ITypeBinding[] parameters = binding.getTypeParameters(); if (parameters.length == 0) return false; return true; }
/** * Given a JDT type binding created by the parser, either replace it with an iOS equivalent, or * return the given type. */ public ITypeBinding mapType(ITypeBinding binding) { if (binding == null) { // happens when mapping a primitive type return null; } // getTypeDeclaration will return the canonical binding for the type with // type parameters and type annotations removed. Note that getErasure() does // not strip type annotations. binding = binding.getTypeDeclaration(); if (binding.isArray()) { return resolveArrayType(binding.getComponentType()); } ITypeBinding newBinding = typeMap.get(binding); if (newBinding == null && binding.isAssignmentCompatible(javaClassType)) { newBinding = typeMap.get(javaClassType); } return newBinding != null ? newBinding : binding; }
public void applyRemoves(ImportRewrite importRewrite) { IBinding[] bindings = getImportsToRemove(); for (int i = 0; i < bindings.length; i++) { if (bindings[i] instanceof ITypeBinding) { ITypeBinding typeBinding = (ITypeBinding) bindings[i]; importRewrite.removeImport(typeBinding.getTypeDeclaration().getQualifiedName()); } else if (bindings[i] instanceof IMethodBinding) { IMethodBinding binding = (IMethodBinding) bindings[i]; importRewrite.removeStaticImport( binding.getDeclaringClass().getQualifiedName() + '.' + binding.getName()); } else if (bindings[i] instanceof IVariableBinding) { IVariableBinding binding = (IVariableBinding) bindings[i]; importRewrite.removeStaticImport( binding.getDeclaringClass().getQualifiedName() + '.' + binding.getName()); } } }
/** * Finds the declaration for a given method and receiver in the same way that the ObjC compiler * will search for a declaration. */ private IMethodBinding getFirstDeclaration(String methodSig, ITypeBinding type) { if (type == null) { return null; } type = type.getTypeDeclaration(); for (IMethodBinding declaredMethod : type.getDeclaredMethods()) { if (methodSig.equals(getObjCMethodSignature(declaredMethod))) { return declaredMethod; } } List<ITypeBinding> supertypes = Lists.newArrayList(); supertypes.addAll(Arrays.asList(type.getInterfaces())); supertypes.add(type.isTypeVariable() ? 0 : supertypes.size(), type.getSuperclass()); for (ITypeBinding supertype : supertypes) { IMethodBinding result = getFirstDeclaration(methodSig, supertype); if (result != null) { return result; } } return null; }
public static ITypeBinding canonicalType(ITypeBinding type) { // This will give us the proper generic type, even if the // original type is RAW or instantiated. while (type != type.getTypeDeclaration()) type = type.getTypeDeclaration(); return type; }
/** Returns whether a given type has an iOS equivalent. */ public boolean hasIOSEquivalent(ITypeBinding binding) { return binding.isArray() || typeMap.containsKey(binding.getTypeDeclaration()); }