Search in sources :

Example 56 with ReturnStatement

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;
}
Also used : MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) VariableDeclarationFragment(org.eclipse.jdt.core.dom.VariableDeclarationFragment) ReturnStatement(org.eclipse.jdt.core.dom.ReturnStatement) Block(org.eclipse.jdt.core.dom.Block) VariableDeclarationStatement(org.eclipse.jdt.core.dom.VariableDeclarationStatement) CastExpression(org.eclipse.jdt.core.dom.CastExpression) SuperMethodInvocation(org.eclipse.jdt.core.dom.SuperMethodInvocation)

Example 57 with ReturnStatement

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;
}
Also used : ReturnStatement(org.eclipse.jdt.core.dom.ReturnStatement)

Example 58 with ReturnStatement

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;
}
Also used : MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) ReturnStatement(org.eclipse.jdt.core.dom.ReturnStatement) Block(org.eclipse.jdt.core.dom.Block)

Example 59 with ReturnStatement

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;
}
Also used : Expression(org.eclipse.jdt.core.dom.Expression) ReturnStatement(org.eclipse.jdt.core.dom.ReturnStatement)

Example 60 with ReturnStatement

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;
}
Also used : IEntity(org.whole.lang.model.IEntity) TryStatement(org.eclipse.jdt.core.dom.TryStatement) Expression(org.eclipse.jdt.core.dom.Expression) ReturnStatement(org.eclipse.jdt.core.dom.ReturnStatement)

Aggregations

ReturnStatement (org.eclipse.jdt.core.dom.ReturnStatement)76 Block (org.eclipse.jdt.core.dom.Block)46 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)39 Expression (org.eclipse.jdt.core.dom.Expression)37 AST (org.eclipse.jdt.core.dom.AST)31 ASTNode (org.eclipse.jdt.core.dom.ASTNode)31 Type (org.eclipse.jdt.core.dom.Type)26 VariableDeclarationStatement (org.eclipse.jdt.core.dom.VariableDeclarationStatement)25 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)23 SimpleName (org.eclipse.jdt.core.dom.SimpleName)22 Statement (org.eclipse.jdt.core.dom.Statement)22 ExpressionStatement (org.eclipse.jdt.core.dom.ExpressionStatement)21 LambdaExpression (org.eclipse.jdt.core.dom.LambdaExpression)16 VariableDeclarationFragment (org.eclipse.jdt.core.dom.VariableDeclarationFragment)16 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)15 PrimitiveType (org.eclipse.jdt.core.dom.PrimitiveType)15 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)14 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)14 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)14 SingleVariableDeclaration (org.eclipse.jdt.core.dom.SingleVariableDeclaration)14