use of org.eclipse.jdt.core.dom.ReturnStatement in project whole by wholeplatform.
the class CompilationUnitBuilder method newCloneMethod.
public MethodDeclaration newCloneMethod() {
MethodDeclaration cloneMethod = ast.newMethodDeclaration();
cloneMethod.setConstructor(false);
cloneMethod.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
cloneMethod.setReturnType2(ast.newSimpleType(newSimpleName("java.lang.Object")));
cloneMethod.setName(ast.newSimpleName("clone"));
Block body = newBlock();
CastExpression castExp = ast.newCastExpression();
castExp.setType(newType(typeDec.getName().getIdentifier()));
SuperMethodInvocation superCall = ast.newSuperMethodInvocation();
superCall.setName(ast.newSimpleName("clone"));
castExp.setExpression(superCall);
VariableDeclarationFragment varDec = ast.newVariableDeclarationFragment();
varDec.setName(ast.newSimpleName("obj"));
varDec.setInitializer(castExp);
VariableDeclarationStatement varDecStm = ast.newVariableDeclarationStatement(varDec);
varDecStm.setType(newType(typeDec.getName().getIdentifier()));
body.statements().add(varDecStm);
ReturnStatement returnStm = ast.newReturnStatement();
returnStm.setExpression(ast.newSimpleName("obj"));
body.statements().add(returnStm);
cloneMethod.setBody(body);
return cloneMethod;
}
use of org.eclipse.jdt.core.dom.ReturnStatement in project whole by wholeplatform.
the class CompilationUnitBuilder method newReturnStatement.
public ReturnStatement newReturnStatement(Expression exp) {
ReturnStatement stm = ast.newReturnStatement();
stm.setExpression(exp);
return stm;
}
use of org.eclipse.jdt.core.dom.ReturnStatement in project whole by wholeplatform.
the class CompilationUnitBuilder method newGetterMethod.
public MethodDeclaration newGetterMethod(String fType, String fName) {
MethodDeclaration method = ast.newMethodDeclaration();
method.setConstructor(false);
method.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
method.setReturnType2(newType(fType));
method.setName(ast.newSimpleName(StringUtils.getterName(fType, fName)));
if (!isInterface) {
Block body = newBlock();
ReturnStatement returnStm = ast.newReturnStatement();
returnStm.setExpression(ast.newSimpleName(fName));
body.statements().add(returnStm);
method.setBody(body);
}
return method;
}
use of org.eclipse.jdt.core.dom.ReturnStatement in project whole by wholeplatform.
the class SimpleEntityImplBuilder method hashCodeMethod.
private MethodDeclaration hashCodeMethod(Expression exp) {
if (hashCodeMethod == null) {
hashCodeMethod = newMethodDeclaration("int", "wHashCode");
hashCodeMethod.getBody().statements().add(newReturnStatement(exp));
addBodyDeclaration(hashCodeMethod);
} else {
ReturnStatement stm = (ReturnStatement) hashCodeMethod.getBody().statements().get(0);
Expression oldExp = stm.getExpression();
stm.setExpression(null);
stm.setExpression(newInfixExpression(oldExp, "+", newInfixExpression(newLiteral(29), "*", exp)));
}
return hashCodeMethod;
}
use of org.eclipse.jdt.core.dom.ReturnStatement in project whole by wholeplatform.
the class SimpleEntityImplBuilder method equalsMethod.
private MethodDeclaration equalsMethod(Expression exp) {
if (equalsMethod == null) {
equalsMethod = newMethodDeclaration("boolean", "wEquals", newSingleVariableDeclaration(IEntity.class.getName(), "entity"));
equalsMethod.getBody().statements().add(newIfStatement(newInfixExpression(ast.newThisExpression(), "==", ast.newSimpleName("entity")), newReturnStatement(newLiteral(true))));
equalsMethod.getBody().statements().add(newIfStatement(newPrefixExpression(newMethodInvocation(newMethodInvocation("wGetEntityDescriptor"), "equals", newMethodInvocation("entity", "wGetEntityDescriptor")), "!"), newReturnStatement(newLiteral(false))));
equalsMethod.getBody().statements().add(newTryStatement(newReturnStatement(exp), newSingleVariableDeclaration("Exception", "e"), newReturnStatement(newLiteral(false))));
addBodyDeclaration(equalsMethod);
} else {
TryStatement tryStm = (TryStatement) equalsMethod.getBody().statements().get(2);
ReturnStatement stm = (ReturnStatement) tryStm.getBody().statements().get(0);
Expression oldExp = stm.getExpression();
stm.setExpression(null);
stm.setExpression(newInfixExpression(oldExp, "&&", exp));
}
return equalsMethod;
}
Aggregations