use of org.eclipse.jdt.core.dom.Dimension 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.Dimension 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.Dimension in project generator by mybatis.
the class TypeStringifier method visit.
@Override
@SuppressWarnings("unchecked")
public boolean visit(ArrayType node) {
node.getElementType().accept(this);
List<Dimension> dimensions = node.dimensions();
for (Dimension dimension : dimensions) {
dimension.accept(this);
}
return false;
}
use of org.eclipse.jdt.core.dom.Dimension in project che by eclipse.
the class SelfEncapsulateFieldRefactoring method createSetterMethod.
private MethodDeclaration createSetterMethod(AST ast, ASTRewrite rewriter, String lineDelimiter) throws CoreException {
FieldDeclaration field = (FieldDeclaration) ASTNodes.getParent(fFieldDeclaration, FieldDeclaration.class);
Type type = field.getType();
MethodDeclaration result = ast.newMethodDeclaration();
result.setName(ast.newSimpleName(fSetterName));
result.modifiers().addAll(ASTNodeFactory.newModifiers(ast, createModifiers()));
if (fSetterMustReturnValue) {
result.setReturnType2((Type) rewriter.createCopyTarget(type));
}
SingleVariableDeclaration param = ast.newSingleVariableDeclaration();
result.parameters().add(param);
param.setName(ast.newSimpleName(fArgName));
param.setType((Type) rewriter.createCopyTarget(type));
List<Dimension> extraDimensions = DimensionRewrite.copyDimensions(fFieldDeclaration.extraDimensions(), rewriter);
param.extraDimensions().addAll(extraDimensions);
Block block = ast.newBlock();
result.setBody(block);
String fieldAccess = createFieldAccess();
String body = CodeGeneration.getSetterMethodBodyContent(fField.getCompilationUnit(), getTypeName(field.getParent()), fSetterName, fieldAccess, fArgName, lineDelimiter);
if (body != null) {
ASTNode setterNode = rewriter.createStringPlaceholder(body, ASTNode.BLOCK);
block.statements().add(setterNode);
} else {
Assignment ass = ast.newAssignment();
ass.setLeftHandSide((Expression) rewriter.createStringPlaceholder(fieldAccess, ASTNode.QUALIFIED_NAME));
ass.setRightHandSide(ast.newSimpleName(fArgName));
block.statements().add(ass);
}
if (fSetterMustReturnValue) {
ReturnStatement rs = ast.newReturnStatement();
rs.setExpression(ast.newSimpleName(fArgName));
block.statements().add(rs);
}
if (fGenerateJavadoc) {
String string = CodeGeneration.getSetterComment(fField.getCompilationUnit(), getTypeName(field.getParent()), fSetterName, fField.getElementName(), ASTNodes.asString(type), fArgName, StubUtility.getBaseName(fField), lineDelimiter);
if (string != null) {
Javadoc javadoc = (Javadoc) fRewriter.createStringPlaceholder(string, ASTNode.JAVADOC);
result.setJavadoc(javadoc);
}
}
return result;
}
use of org.eclipse.jdt.core.dom.Dimension in project che by eclipse.
the class PromoteTempToFieldRefactoring method createNewFieldDeclaration.
private FieldDeclaration createNewFieldDeclaration(ASTRewrite rewrite) {
AST ast = getAST();
VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment();
SimpleName variableName = ast.newSimpleName(fFieldName);
fragment.setName(variableName);
addLinkedName(rewrite, variableName, false);
List<Dimension> extraDimensions = DimensionRewrite.copyDimensions(fTempDeclarationNode.extraDimensions(), rewrite);
fragment.extraDimensions().addAll(extraDimensions);
if (fInitializeIn == INITIALIZE_IN_FIELD && tempHasInitializer()) {
Expression initializer = (Expression) rewrite.createCopyTarget(getTempInitializer());
fragment.setInitializer(initializer);
}
FieldDeclaration fieldDeclaration = ast.newFieldDeclaration(fragment);
VariableDeclarationStatement vds = getTempDeclarationStatement();
Type type = (Type) rewrite.createCopyTarget(vds.getType());
fieldDeclaration.setType(type);
fieldDeclaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, getModifiers()));
return fieldDeclaration;
}
Aggregations