/** * Returns the new type node corresponding to the type of the given declaration * including the extra dimensions. * @param ast The AST to create the resulting type with. * @param declaration The variable declaration to get the type from * @return A new type node created with the given AST. */ public static Type newType(AST ast, VariableDeclaration declaration) { Type type= ASTNodes.getType(declaration); int extraDim= declaration.getExtraDimensions(); type= (Type) ASTNode.copySubtree(ast, type); for (int i= 0; i < extraDim; i++) { type= ast.newArrayType(type); } return type; }
/** * Returns a Type that describes the given ITypeBinding. If the binding * refers to an object type, use the import rewriter to determine whether * the reference requires a new import, or instead needs to be qualified.<br> * Like ASTNodeFactory.newType(), but for the handling of imports. * @param extraDims number of extra array dimensions to add to the resulting type */ private Type typeNodeForTypeBinding(ITypeBinding argType, int extraDims, AST ast) { if (extraDims > 0) { return ast.newArrayType(typeNodeForTypeBinding(argType, 0, ast), extraDims); } else if (argType.isArray()) { Type elementType= typeNodeForTypeBinding(argType.getElementType(), extraDims, ast); return ast.newArrayType(elementType, argType.getDimensions()); } else { return fImportRewriter.addImport(argType, ast); } }
/** * @param argType * @param extraDims number of extra array dimensions to add to the resulting type * @param ast * @return a Type that describes the given ITypeBinding. If the binding * refers to an object type, use the import rewriter to determine whether * the reference requires a new import, or instead needs to be qualified.<br> * Like ASTNodeFactory.newType(), but for the handling of imports. */ private Type typeNodeForTypeBinding(ITypeBinding argType, int extraDims, AST ast) { if (extraDims > 0) { return ast.newArrayType(typeNodeForTypeBinding(argType, 0, ast), extraDims); } else if (argType.isArray()) { Type elementType= typeNodeForTypeBinding(argType.getElementType(), extraDims, ast); return ast.newArrayType(elementType, argType.getDimensions()); } else { return fImportRewriter.addImport(argType, ast); } }
/** * Returns an {@link ArrayType} that adds one dimension to the given type node. * If the given node is already an ArrayType, then a new {@link Dimension} * without annotations is inserted at the first position. * * @param type the type to be wrapped * @return the array type * @since 3.10 */ public static ArrayType newArrayType(Type type) { if (type instanceof ArrayType) { Dimension dimension= type.getAST().newDimension(); ArrayType arrayType= (ArrayType) type; arrayType.dimensions().add(0, dimension); // first dimension is outermost return arrayType; } else { return type.getAST().newArrayType(type); } }
/** * Returns the array type in this array creation expression. * * @return the array type */ public ArrayType getType() { if (this.arrayType == null) { // lazy init must be thread-safe for readers synchronized (this) { if (this.arrayType == null) { preLazyInit(); this.arrayType = this.ast.newArrayType( this.ast.newPrimitiveType(PrimitiveType.INT)); postLazyInit(this.arrayType, TYPE_PROPERTY); } } } return this.arrayType; }
/** * @param argType * @param extraDims number of extra array dimensions to add to the resulting type * @param ast * @return a Type that describes the given ITypeBinding. If the binding * refers to an object type, use the import rewriter to determine whether * the reference requires a new import, or instead needs to be qualified.<br> * Like ASTNodeFactory.newType(), but for the handling of imports. */ private Type typeNodeForTypeBinding(ITypeBinding argType, int extraDims, AST ast) { if (extraDims > 0) { return ast.newArrayType(typeNodeForTypeBinding(argType, 0, ast), extraDims); } else if (argType.isArray()) { Type elementType= typeNodeForTypeBinding(argType.getElementType(), extraDims, ast); return ast.newArrayType(elementType, argType.getDimensions()); } else { return fImportRewriter.addImport(argType, ast); } }
/** * Returns the array type in this array creation expression. * * @return the array type */ public ArrayType getType() { if (this.arrayType == null) { // lazy init must be thread-safe for readers synchronized (this) { if (this.arrayType == null) { preLazyInit(); this.arrayType = this.ast.newArrayType( this.ast.newPrimitiveType(PrimitiveType.INT)); postLazyInit(this.arrayType, TYPE_PROPERTY); } } } return this.arrayType; }
/** * Returns the array type in this array creation expression. * * @return the array type */ public ArrayType getType() { if (this.arrayType == null) { // lazy init must be thread-safe for readers synchronized (this) { if (this.arrayType == null) { preLazyInit(); this.arrayType = this.ast.newArrayType( this.ast.newPrimitiveType(PrimitiveType.INT)); postLazyInit(this.arrayType, TYPE_PROPERTY); } } } return this.arrayType; }
/** * Returns the array type in this array creation expression. * * @return the array type */ public ArrayType getType() { if (this.arrayType == null) { // lazy init must be thread-safe for readers synchronized (this) { if (this.arrayType == null) { preLazyInit(); this.arrayType = this.ast.newArrayType( this.ast.newPrimitiveType(PrimitiveType.INT)); postLazyInit(this.arrayType, TYPE_PROPERTY); } } } return this.arrayType; }
/** * Returns the array type in this array creation expression. * * @return the array type */ public ArrayType getType() { if (this.arrayType == null) { // lazy init must be thread-safe for readers synchronized (this) { if (this.arrayType == null) { preLazyInit(); this.arrayType = this.ast.newArrayType( this.ast.newPrimitiveType(PrimitiveType.INT)); postLazyInit(this.arrayType, TYPE_PROPERTY); } } } return this.arrayType; }
/** * Returns an {@link ArrayType} that adds one dimension to the given type node. * If the given node is already an ArrayType, then a new {@link Dimension} * without annotations is inserted at the first position. * * @param type the type to be wrapped * @return the array type * @since 3.10 */ public static ArrayType newArrayType(Type type) { if (type instanceof ArrayType) { Dimension dimension= type.getAST().newDimension(); ArrayType arrayType= (ArrayType) type; arrayType.dimensions().add(0, dimension); // first dimension is outermost return arrayType; } else { return type.getAST().newArrayType(type); } }
/** * Returns the array type in this array creation expression. * * @return the array type */ public ArrayType getType() { if (this.arrayType == null) { // lazy init must be thread-safe for readers synchronized (this) { if (this.arrayType == null) { preLazyInit(); this.arrayType = this.ast.newArrayType( this.ast.newPrimitiveType(PrimitiveType.INT)); postLazyInit(this.arrayType, TYPE_PROPERTY); } } } return this.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) { 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; }
/** * Create new instance of array type. * * @param type base type name * @return array creation */ public NewArrayBuilder newArrayBuilder(String type) { ArrayCreation create = getAST().newArrayCreation(); create.setType(getAST().newArrayType(m_source.createType(type))); return new NewArrayBuilder(this, create); }
@Override public boolean visit(SingleVariableDeclaration node) { AST ast = node.getAST(); if (node.getExtraDimensions() > 0) { Type type = (Type) ASTNode.copySubtree(ast, node.getType()); for (int i = node.getExtraDimensions(); i > 0; i--) { type = ast.newArrayType(type); } node.setType(type); node.setExtraDimensions(0); } return true; } }
private Type copyType(final Type type) { switch (type.getNodeType()) { case ARRAY_TYPE: final ArrayType arrayType = (ArrayType) type; return ast.newArrayType( copyType(arrayType.getElementType()), arrayType.getDimensions()); case PRIMITIVE_TYPE: final Code code = ((PrimitiveType) type).getPrimitiveTypeCode(); return ast.newPrimitiveType(code); case QUALIFIED_TYPE: return type(type.resolveBinding().getQualifiedName()); case SIMPLE_TYPE: final SimpleType sType = (SimpleType) type; return ast.newSimpleType(copy(sType.getName())); } throw new NotImplementedException(null, "Unknown type for type " + type); }