use of org.eclipse.jdt.core.dom.FieldDeclaration in project AutoRefactor by JnRouvignac.
the class ASTBuilder method declareField.
/**
* Builds a new {@link FieldDeclaration} instance.
*
* @param type
* the declared variable type
* @param fragment
* the variable declaration fragment
* @return a new field declaration
*/
public FieldDeclaration declareField(Type type, VariableDeclarationFragment fragment) {
final FieldDeclaration fd = ast.newFieldDeclaration(fragment);
fd.setType(type);
return fd;
}
use of org.eclipse.jdt.core.dom.FieldDeclaration in project whole by wholeplatform.
the class CompilationUnitBuilder method newSerialVersionUID.
public FieldDeclaration newSerialVersionUID(long value) {
FieldDeclaration field = newFieldDeclaration("long", "serialVersionUID", newLiteral(value));
field.modifiers().add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD));
field.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD));
return field;
}
use of org.eclipse.jdt.core.dom.FieldDeclaration in project whole by wholeplatform.
the class CompilationUnitBuilder method addSingletonMethod.
public MethodDeclaration addSingletonMethod() {
String typeName = typeDec.getName().getIdentifier();
FieldDeclaration instanceField = newFieldDeclaration(typeName, "instance");
instanceField.modifiers().add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD));
addBodyDeclaration(0, instanceField);
MethodDeclaration instanceMethod = newMethodDeclaration(typeName, "instance");
instanceMethod.modifiers().add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD));
addBodyDeclaration(1, instanceMethod);
Block body = newBlock();
IfStatement ifStm = ast.newIfStatement();
InfixExpression infixExp = ast.newInfixExpression();
infixExp.setLeftOperand(ast.newSimpleName("instance"));
infixExp.setOperator(InfixExpression.Operator.EQUALS);
infixExp.setRightOperand(ast.newNullLiteral());
ifStm.setExpression(infixExp);
ifStm.setThenStatement(ast.newExpressionStatement(newAssignment("instance", newClassInstanceCreation(typeName))));
body.statements().add(ifStm);
body.statements().add(newReturnStatement(ast.newSimpleName("instance")));
instanceMethod.setBody(body);
MethodDeclaration constructor = newConstructorDeclaration(typeDec);
// assume ModifierKeyword.PUBLIC_KEYWORD
constructor.modifiers().remove(0);
constructor.modifiers().add(ast.newModifier(ModifierKeyword.PRIVATE_KEYWORD));
addBodyDeclaration(2, constructor);
return constructor;
}
use of org.eclipse.jdt.core.dom.FieldDeclaration in project whole by wholeplatform.
the class CompilationUnitBuilder method addSingletonHolder.
public TypeDeclaration addSingletonHolder(String holderName, String fieldTypeName, List<BodyDeclaration> declarations) {
TypeDeclaration classDeclaration = ast.newTypeDeclaration();
classDeclaration.modifiers().add(ast.newModifier(ModifierKeyword.PRIVATE_KEYWORD));
classDeclaration.modifiers().add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD));
classDeclaration.setName(ast.newSimpleName(holderName));
VariableDeclarationFragment varDec = newVariableDeclarationFragment("instance", newClassInstanceCreation(fieldTypeName));
FieldDeclaration instanceField = ast.newFieldDeclaration(varDec);
instanceField.modifiers().add(ast.newModifier(ModifierKeyword.PRIVATE_KEYWORD));
instanceField.modifiers().add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD));
instanceField.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD));
instanceField.setType(ast.newSimpleType(ast.newSimpleName(fieldTypeName)));
classDeclaration.bodyDeclarations().add(instanceField);
classDeclaration.bodyDeclarations().addAll(declarations);
addBodyDeclaration(classDeclaration);
return classDeclaration;
}
use of org.eclipse.jdt.core.dom.FieldDeclaration in project whole by wholeplatform.
the class EntityDescriptorEnumBuilder method addMapEntity.
@SuppressWarnings("unchecked")
public void addMapEntity(String eType, String name, Set<String> modifiers, String keyType, String valueType) {
String eName = StringUtils.toSimpleName(eType);
String eName_Ord = eName + "_ord";
String oldType = entities.put(eName, eType);
if (oldType == null) {
// public static final int [eName_ord] = [nextOrdinal];
FieldDeclaration fieldDecl = newFieldDeclaration("int", eName_Ord, newLiteral(nextOrdinal));
// assume ModifierKeyword.PRIVATE_KEYWORD
fieldDecl.modifiers().remove(0);
fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD));
fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD));
addBodyDeclaration(nextOrdinal++, fieldDecl);
// public static final EntityDescriptor<eName> [eName] = (EntityDescriptor<eName>) instance.valueOf([eName_ord]);
fieldDecl = newFieldDeclaration(newParameterizedType(EntityDescriptor.class.getName(), eName), newVariableDeclarationFragment(eName, newCastExpression(newParameterizedType(EntityDescriptor.class.getName(), eName), newMethodInvocation("instance", "valueOf", ast.newSimpleName(eName_Ord)))));
// assume ModifierKeyword.PRIVATE_KEYWORD
fieldDecl.modifiers().remove(0);
fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.STATIC_KEYWORD));
fieldDecl.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD));
addBodyDeclaration(nextOrdinal * 2, fieldDecl);
} else if (oldType.equals(eType))
return;
// putMapEntity([eName_ord], "[eName]", [eType].class, ElementType_ord);
MethodInvocation callExp = newMethodInvocation("putMapEntity");
callExp.arguments().add(ast.newSimpleName(eName_Ord));
callExp.arguments().add(newLiteral(name));
if (!eName.equals(name))
callExp.arguments().add(newLiteral(eName));
callExp.arguments().add(newTypeLiteral(eType));
callExp.arguments().add(newLiteral(modifiers != null && modifiers.contains("RELATIONSHIP")));
// newEnumSetOfExpression(EntityModifiers.class.getName(), modifiers));
callExp.arguments().add(ast.newSimpleName(generator.entityResolverSimpleName(keyType) + "_ord"));
callExp.arguments().add(ast.newSimpleName(generator.entityResolverSimpleName(valueType) + "_ord"));
ExpressionStatement expStm = newExpressionStatement(callExp);
initEntityDescriptors.getBody().statements().add(expStm);
etypeExpressionMap.put(eType, expStm);
}
Aggregations