use of org.eclipse.jdt.core.dom.ArrayType in project flux by eclipse.
the class ASTNodeFactory method newCreationType.
public static Type newCreationType(AST ast, ITypeBinding typeBinding, ImportRewrite importRewrite, ImportRewriteContext importContext) {
if (typeBinding.isParameterizedType()) {
Type baseType = newCreationType(ast, typeBinding.getTypeDeclaration(), importRewrite, importContext);
ParameterizedType parameterizedType = ast.newParameterizedType(baseType);
for (ITypeBinding typeArgument : typeBinding.getTypeArguments()) {
parameterizedType.typeArguments().add(newCreationType(ast, typeArgument, importRewrite, importContext));
}
return parameterizedType;
} else if (typeBinding.isParameterizedType()) {
Type elementType = newCreationType(ast, typeBinding.getElementType(), importRewrite, importContext);
ArrayType arrayType = ast.newArrayType(elementType, 0);
while (typeBinding.isArray()) {
Dimension dimension = ast.newDimension();
IAnnotationBinding[] typeAnnotations = typeBinding.getTypeAnnotations();
for (IAnnotationBinding typeAnnotation : typeAnnotations) {
dimension.annotations().add(importRewrite.addAnnotation(typeAnnotation, ast, importContext));
}
arrayType.dimensions().add(dimension);
typeBinding = typeBinding.getComponentType();
}
return arrayType;
} else if (typeBinding.isWildcardType()) {
ITypeBinding bound = typeBinding.getBound();
typeBinding = (bound != null) ? bound : typeBinding.getErasure();
return newCreationType(ast, typeBinding, importRewrite, importContext);
} else {
return importRewrite.addImport(typeBinding, ast, importContext);
}
}
use of org.eclipse.jdt.core.dom.ArrayType in project flux by eclipse.
the class ASTNodeFactory method newType.
/**
* Returns the new type node corresponding to the type of the given declaration
* including the extra dimensions. If the type is a {@link UnionType}, use the LUB type.
* If the <code>importRewrite</code> is <code>null</code>, the type may be fully-qualified.
*
* @param ast The AST to create the resulting type with.
* @param declaration The variable declaration to get the type from
* @param importRewrite the import rewrite to use, or <code>null</code>
* @param context the import rewrite context, or <code>null</code>
* @return a new type node created with the given AST.
*
* @since 3.7.1
*/
public static Type newType(AST ast, VariableDeclaration declaration, ImportRewrite importRewrite, ImportRewriteContext context) {
if (declaration instanceof VariableDeclarationFragment && declaration.getParent() instanceof LambdaExpression) {
return newType((LambdaExpression) declaration.getParent(), (VariableDeclarationFragment) declaration, ast, importRewrite, context);
}
Type type = ASTNodes.getType(declaration);
if (declaration instanceof SingleVariableDeclaration) {
Type type2 = ((SingleVariableDeclaration) declaration).getType();
if (type2 instanceof UnionType) {
ITypeBinding typeBinding = type2.resolveBinding();
if (typeBinding != null) {
if (importRewrite != null) {
type = importRewrite.addImport(typeBinding, ast, context);
return type;
} else {
String qualifiedName = typeBinding.getQualifiedName();
if (qualifiedName.length() > 0) {
type = ast.newSimpleType(ast.newName(qualifiedName));
return type;
}
}
}
// XXX: fallback for intersection types or unresolved types: take first type of union
type = (Type) ((UnionType) type2).types().get(0);
return type;
}
}
type = (Type) ASTNode.copySubtree(ast, type);
List<Dimension> extraDimensions = declaration.extraDimensions();
if (!extraDimensions.isEmpty()) {
ArrayType arrayType;
if (type instanceof ArrayType) {
arrayType = (ArrayType) type;
} else {
arrayType = ast.newArrayType(type, 0);
type = arrayType;
}
arrayType.dimensions().addAll(ASTNode.copySubtrees(ast, extraDimensions));
}
return type;
}
use of org.eclipse.jdt.core.dom.ArrayType in project flux by eclipse.
the class DimensionRewrite method copyTypeAndAddDimensions.
/**
* Creates a {@link ASTRewrite#createCopyTarget(ASTNode) copy} of <code>type</code>
* and adds <code>extraDimensions</code> to it.
*
* @param type the type to copy
* @param extraDimensions the dimensions to add
* @param rewrite the ASTRewrite with which to create new nodes
* @return the copy target with added dimensions
*/
public static Type copyTypeAndAddDimensions(Type type, List<Dimension> extraDimensions, ASTRewrite rewrite) {
AST ast = rewrite.getAST();
if (extraDimensions.isEmpty()) {
return (Type) rewrite.createCopyTarget(type);
}
ArrayType result;
if (type instanceof ArrayType) {
ArrayType arrayType = (ArrayType) type;
Type varElementType = (Type) rewrite.createCopyTarget(arrayType.getElementType());
result = ast.newArrayType(varElementType, 0);
result.dimensions().addAll(copyDimensions(extraDimensions, rewrite));
result.dimensions().addAll(copyDimensions(arrayType.dimensions(), rewrite));
} else {
Type elementType = (Type) rewrite.createCopyTarget(type);
result = ast.newArrayType(elementType, 0);
result.dimensions().addAll(copyDimensions(extraDimensions, rewrite));
}
return result;
}
use of org.eclipse.jdt.core.dom.ArrayType in project xtext-xtend by eclipse.
the class JavaASTFlattener method visit.
@Override
public boolean visit(final ArrayCreation node) {
ArrayType at = node.getType();
int dims = at.getDimensions();
if ((dims > 1)) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("/* FIXME Only one dimensional arrays are supported. ");
_builder.append(node);
_builder.append("*/");
this.appendToBuffer(_builder.toString());
this.addProblem(node, "Only one dimension arrays are supported.");
return false;
}
ArrayInitializer _initializer = node.getInitializer();
boolean _tripleNotEquals = (_initializer != null);
if (_tripleNotEquals) {
if (this.fallBackStrategy) {
this.appendToBuffer("(");
}
node.getInitializer().accept(this);
if (this.fallBackStrategy) {
this.appendToBuffer(" as ");
at.accept(this);
this.appendToBuffer(")");
}
} else {
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("new");
String _xifexpression = null;
boolean _isPrimitiveType = node.getType().getElementType().isPrimitiveType();
if (_isPrimitiveType) {
Type _elementType = node.getType().getElementType();
_xifexpression = StringExtensions.toFirstUpper(((PrimitiveType) _elementType).getPrimitiveTypeCode().toString());
}
_builder_1.append(_xifexpression);
_builder_1.append("ArrayOfSize(");
this.appendToBuffer(_builder_1.toString());
List _dimensions = node.dimensions();
(((Expression[]) Conversions.unwrapArray(((Iterable<Expression>) _dimensions), Expression.class))[0]).accept(this);
this.appendToBuffer(")");
}
return false;
}
use of org.eclipse.jdt.core.dom.ArrayType in project che by eclipse.
the class Java50Fix method createRawTypeReferenceOperations.
private static SimpleType createRawTypeReferenceOperations(CompilationUnit compilationUnit, IProblemLocation[] locations, List<CompilationUnitRewriteOperation> operations) {
if (hasFatalError(compilationUnit))
return null;
List<SimpleType> result = new ArrayList<SimpleType>();
for (int i = 0; i < locations.length; i++) {
IProblemLocation problem = locations[i];
if (isRawTypeReferenceProblem(problem.getProblemId())) {
ASTNode node = problem.getCoveredNode(compilationUnit);
if (node instanceof ClassInstanceCreation) {
Type rawReference = (Type) node.getStructuralProperty(ClassInstanceCreation.TYPE_PROPERTY);
if (isRawTypeReference(rawReference)) {
result.add((SimpleType) rawReference);
}
} else if (node instanceof SimpleName) {
ASTNode rawReference = node.getParent();
if (isRawTypeReference(rawReference)) {
ASTNode parent = rawReference.getParent();
if (!(parent instanceof ArrayType || parent instanceof ParameterizedType))
result.add((SimpleType) rawReference);
}
} else if (node instanceof MethodInvocation) {
MethodInvocation invocation = (MethodInvocation) node;
SimpleType rawReference = getRawReference(invocation, compilationUnit);
if (rawReference != null) {
result.add(rawReference);
}
}
}
}
if (result.size() == 0)
return null;
SimpleType[] types = result.toArray(new SimpleType[result.size()]);
operations.add(new AddTypeParametersOperation(types));
return types[0];
}
Aggregations