List of usage examples for org.eclipse.jdt.core.dom SingleVariableDeclaration setModifiers
public void setModifiers(int modifiers)
From source file:org.smartfrog.tools.eclipse.ui.project.document.BaseComponentCreationWizardPage.java
License:Open Source License
/** * add smartFrog methods to template (memory only) * @param cu//from w ww . ja v a2 s . co m * @param unit * @param typeDeclaration * @param methodName * @param needToThrow * @param needParam * @throws CoreException * @throws InterruptedException */ private void addSfDeployMethod(ICompilationUnit cu, CompilationUnit unit, TypeDeclaration typeDeclaration, String methodName, boolean needToThrow, boolean needParam) throws CoreException, InterruptedException { AST localAst = typeDeclaration.getAST(); MethodDeclaration methodDeclaration = localAst.newMethodDeclaration(); methodDeclaration.setConstructor(false); methodDeclaration.setModifiers(Modifier.PUBLIC | Modifier.SYNCHRONIZED); methodDeclaration.setName(localAst.newSimpleName(methodName)); methodDeclaration.setReturnType(localAst.newPrimitiveType(PrimitiveType.VOID)); if (needParam) { SingleVariableDeclaration variableDeclaration = localAst.newSingleVariableDeclaration(); variableDeclaration.setModifiers(Modifier.NONE); variableDeclaration.setType(localAst.newSimpleType(localAst.newSimpleName(TERMINATIONRECORD_VAR))); variableDeclaration.setName(localAst.newSimpleName(SFTERMINATE_STATUS_ARGUMENT_NAME)); methodDeclaration.parameters().add(variableDeclaration); } Block block = localAst.newBlock(); methodDeclaration.setBody(block); SuperMethodInvocation superMethodInvocation = localAst.newSuperMethodInvocation(); superMethodInvocation.setName(localAst.newSimpleName(methodName)); if (needParam) { List list = superMethodInvocation.arguments(); list.add(localAst.newSimpleName(SFTERMINATE_STATUS_ARGUMENT_NAME)); } ExpressionStatement expressionStatement = localAst.newExpressionStatement(superMethodInvocation); block.statements().add(expressionStatement); if (needToThrow) { List throwsExceptions = methodDeclaration.thrownExceptions(); throwsExceptions.add(localAst.newSimpleName(SMARTFROGEXCEPTION_NAME)); throwsExceptions.add(localAst.newSimpleName(REMOTEEXCEPTION_NAME)); } typeDeclaration.bodyDeclarations().add(methodDeclaration); }