private static ITypeBinding getReducedDimensionBinding(ITypeBinding arrayBinding, int dimsToReduce) { while (dimsToReduce > 0) { arrayBinding= arrayBinding.getComponentType(); dimsToReduce--; } return arrayBinding; }
private static ITypeBinding getReducedDimensionBinding(ITypeBinding arrayBinding, int dimsToReduce) { while (dimsToReduce > 0) { arrayBinding= arrayBinding.getComponentType(); dimsToReduce--; } return arrayBinding; }
public static ITypeBinding getReducedDimensionBinding(ITypeBinding arrayBinding, int dimsToReduce) { while (dimsToReduce > 0) { arrayBinding= arrayBinding.getComponentType(); dimsToReduce--; } return arrayBinding; }
/** * Returns the n-th component type of the given type, or <code>null</code> if * the type binding is not an array type or has not that many dimensions. * * @param arrayType an array type binding * @param n number of dimensions to cut * @return arrayType with n dimensions removed, or <code>null</code> * @since 3.10 */ public static ITypeBinding getComponentType(ITypeBinding arrayType, int n) { ITypeBinding type= arrayType; while (n > 0 && type != null) { type= type.getComponentType(); n--; } return type; }
/** * Returns the n-th component type of the given type, or <code>null</code> if * the type binding is not an array type or has not that many dimensions. * * @param arrayType an array type binding * @param n number of dimensions to cut * @return arrayType with n dimensions removed, or <code>null</code> * @since 3.10 */ public static ITypeBinding getComponentType(ITypeBinding arrayType, int n) { ITypeBinding type= arrayType; while (n > 0 && type != null) { type= type.getComponentType(); n--; } return type; }
private JdtJavaArrayType(ITypeBinding arrayType) { super(); fEltJdtType = arrayType.getComponentType(); fEltCAstType = getCAstTypeFor(fEltJdtType); }
private static ITypeBinding getParameterTypeBinding(ASTNode node, List args, IMethodBinding binding) { ITypeBinding[] paramTypes= binding.getParameterTypes(); int index= args.indexOf(node); if (binding.isVarargs() && index >= paramTypes.length - 1) { return paramTypes[paramTypes.length - 1].getComponentType(); } if (index >= 0 && index < paramTypes.length) { return paramTypes[index]; } return null; }
public static ITypeBinding getParameterTypeBinding(IMethodBinding methodBinding, int argumentIndex) { ITypeBinding[] paramTypes= methodBinding.getParameterTypes(); if (methodBinding.isVarargs() && argumentIndex >= paramTypes.length - 1) { return paramTypes[paramTypes.length - 1].getComponentType(); } if (argumentIndex >= 0 && argumentIndex < paramTypes.length) { return paramTypes[argumentIndex]; } return null; }
public static ITypeBinding getParameterTypeBinding(IMethodBinding methodBinding, int argumentIndex) { ITypeBinding[] paramTypes= methodBinding.getParameterTypes(); if (methodBinding.isVarargs() && argumentIndex >= paramTypes.length - 1) { return paramTypes[paramTypes.length - 1].getComponentType(); } if (argumentIndex >= 0 && argumentIndex < paramTypes.length) { return paramTypes[argumentIndex]; } return null; }
private boolean areTypeCompatible(ITypeBinding colTypeBinding, ITypeBinding arrayTypeBinding) { if (arrayTypeBinding != null && colTypeBinding != null) { ITypeBinding jucTypeBinding = findImplementedType(colTypeBinding, "java.util.Collection"); if (jucTypeBinding.isRawType()) { return true; } ITypeBinding componentType = arrayTypeBinding.getComponentType(); ITypeBinding colTypeArgument = jucTypeBinding.getTypeArguments()[0]; return componentType.isSubTypeCompatible(colTypeArgument); } return false; }
private Type getArrayType(Type elementType, AST ast, ImportRewriteContext context, ITypeBinding normalizedBinding) { int noDimensions = normalizedBinding.getDimensions(); ArrayType arrayType = ast.newArrayType(elementType, noDimensions); if (ast.apiLevel() >= AST.JLS8) { for (int i = 0; i < noDimensions; i++) { IAnnotationBinding[] typeAnnotations = normalizedBinding.getTypeAnnotations(); if (typeAnnotations.length > 0) { Dimension dimension = (Dimension) arrayType.dimensions().get(i); annotateList(dimension.annotations(), typeAnnotations, ast, context); } normalizedBinding = normalizedBinding.getComponentType(); } } return arrayType; }
private Type getArrayType(Type elementType, AST ast, ImportRewriteContext context, ITypeBinding normalizedBinding) { int noDimensions = normalizedBinding.getDimensions(); ArrayType arrayType = ast.newArrayType(elementType, noDimensions); if (ast.apiLevel() >= AST.JLS8) { for (int i = 0; i < noDimensions; i++) { IAnnotationBinding[] typeAnnotations = normalizedBinding.getTypeAnnotations(); if (typeAnnotations.length > 0) { Dimension dimension = (Dimension) arrayType.dimensions().get(i); annotateList(dimension.annotations(), typeAnnotations, ast, context); } normalizedBinding = normalizedBinding.getComponentType(); } } return arrayType; }
private Type getArrayType(Type elementType, AST ast, ImportRewriteContext context, ITypeBinding normalizedBinding) { int noDimensions = normalizedBinding.getDimensions(); ArrayType arrayType = ast.newArrayType(elementType, noDimensions); if (ast.apiLevel() >= AST.JLS8) { for (int i = 0; i < noDimensions; i++) { IAnnotationBinding[] typeAnnotations = normalizedBinding.getTypeAnnotations(); if (typeAnnotations.length > 0) { Dimension dimension = (Dimension) arrayType.dimensions().get(i); annotateList(dimension.annotations(), typeAnnotations, ast, context); } normalizedBinding = normalizedBinding.getComponentType(); } } return arrayType; }
private Type getArrayType(Type elementType, AST ast, ImportRewriteContext context, ITypeBinding normalizedBinding, TypeLocation location) { int noDimensions = normalizedBinding.getDimensions(); ArrayType arrayType = ast.newArrayType(elementType, noDimensions); if (ast.apiLevel() >= JLS8_INTERNAL) { for (int i = 0; i < noDimensions; i++) { IAnnotationBinding[] typeAnnotations = normalizedBinding.getTypeAnnotations(); if (typeAnnotations.length > 0) { Dimension dimension = (Dimension) arrayType.dimensions().get(i); annotateList(dimension.annotations(), typeAnnotations, ast, context, i == 0 ? location : TypeLocation.ARRAY_CONTENTS, normalizedBinding); } normalizedBinding = normalizedBinding.getComponentType(); } } return arrayType; }
private Type getArrayType(Type elementType, AST ast, ImportRewriteContext context, ITypeBinding normalizedBinding, TypeLocation location) { int noDimensions = normalizedBinding.getDimensions(); ArrayType arrayType = ast.newArrayType(elementType, noDimensions); if (ast.apiLevel() >= JLS8_INTERNAL) { for (int i = 0; i < noDimensions; i++) { IAnnotationBinding[] typeAnnotations = normalizedBinding.getTypeAnnotations(); if (typeAnnotations.length > 0) { Dimension dimension = (Dimension) arrayType.dimensions().get(i); annotateList(dimension.annotations(), typeAnnotations, ast, context, i == 0 ? location : TypeLocation.ARRAY_CONTENTS, normalizedBinding); } normalizedBinding = normalizedBinding.getComponentType(); } } return arrayType; }
/** * Extracts the type parameter of the variable contained in fCurrentExpression or the elements * type to iterate over an array using <code>foreach</code>. * * @param ast the current {@link AST} instance * @return the {@link ITypeBinding} of the elements to iterate over */ private ITypeBinding extractType(AST ast) { if (fExpressionType.isArray()) { return Bindings.normalizeForDeclarationUse(fExpressionType.getComponentType(), ast); } // extract elements type directly out of the bindings IMethodBinding iteratorMethodBinding= Bindings.findMethodInHierarchy(fExpressionType, "iterator", new ITypeBinding[] {}); //$NON-NLS-1$ IMethodBinding iteratorNextMethodBinding= Bindings.findMethodInHierarchy(iteratorMethodBinding.getReturnType(), "next", new ITypeBinding[] {}); //$NON-NLS-1$ ITypeBinding currentElementBinding= iteratorNextMethodBinding.getReturnType(); return Bindings.normalizeForDeclarationUse(currentElementBinding, ast); }
private void copyArguments(MethodDeclaration intermediary, CompilationUnitRewrite rew, ImportRewriteContext context) throws JavaModelException { String[] names= fTargetMethod.getParameterNames(); ITypeBinding[] types= fTargetMethodBinding.getParameterTypes(); for (int i= 0; i < names.length; i++) { ITypeBinding typeBinding= types[i]; SingleVariableDeclaration newElement= rew.getAST().newSingleVariableDeclaration(); newElement.setName(rew.getAST().newSimpleName(names[i])); if (i == (names.length - 1) && fTargetMethodBinding.isVarargs()) { newElement.setVarargs(true); if (typeBinding.isArray()) typeBinding= typeBinding.getComponentType(); } newElement.setType(rew.getImportRewrite().addImport(typeBinding, rew.getAST(), context)); intermediary.parameters().add(newElement); } }
private void copyArguments(MethodDeclaration intermediary, CompilationUnitRewrite rew, ImportRewriteContext context) throws JavaModelException { String[] names= fTargetMethod.getParameterNames(); ITypeBinding[] types= fTargetMethodBinding.getParameterTypes(); for (int i= 0; i < names.length; i++) { ITypeBinding typeBinding= types[i]; SingleVariableDeclaration newElement= rew.getAST().newSingleVariableDeclaration(); newElement.setName(rew.getAST().newSimpleName(names[i])); if (i == (names.length - 1) && fTargetMethodBinding.isVarargs()) { newElement.setVarargs(true); if (typeBinding.isArray()) typeBinding= typeBinding.getComponentType(); } newElement.setType(rew.getImportRewrite().addImport(typeBinding, rew.getAST(), context, TypeLocation.PARAMETER)); intermediary.parameters().add(newElement); } }
private void copyArguments(MethodDeclaration intermediary, CompilationUnitRewrite rew) throws JavaModelException { String[] names= fTargetMethod.getParameterNames(); ITypeBinding[] types= fTargetMethodBinding.getParameterTypes(); for (int i= 0; i < names.length; i++) { ITypeBinding typeBinding= types[i]; SingleVariableDeclaration newElement= rew.getAST().newSingleVariableDeclaration(); newElement.setName(rew.getAST().newSimpleName(names[i])); if (i == (names.length - 1) && fTargetMethodBinding.isVarargs()) { newElement.setVarargs(true); if (typeBinding.isArray()) typeBinding= typeBinding.getComponentType(); } newElement.setType(rew.getImportRewrite().addImport(typeBinding, rew.getAST())); intermediary.parameters().add(newElement); } }
public boolean visit(ArrayInitializer node) { if (isImplicitelyTypedArrayInitializer(node)) { CSArrayCreationExpression ace = new CSArrayCreationExpression(mappedTypeReference(node.resolveTypeBinding() .getComponentType())); ITypeBinding saved = pushExpectedType(node.resolveTypeBinding().getElementType()); ace.initializer(mapArrayInitializer(node)); popExpectedType(saved); pushExpression(ace); return false; } pushExpression(mapArrayInitializer(node)); return false; }