List of usage examples for org.eclipse.jdt.core.dom Block statements
ASTNode.NodeList statements
To view the source code for org.eclipse.jdt.core.dom Block statements.
Click Source Link
From source file:org.modeshape.sequencer.javafile.JdtRecorder.java
License:Apache License
/** * <pre>/* ww w .j a v a 2 s .c om*/ * Initializer: * [ static ] Block * * Block: * { { Statement } } * </pre> * * @param initializer the {@link Initializer initializer} being recorded (cannot be <code>null</code>) * @param nodeName the name of the node being created that represents the initializer (cannot be <code>null</code> or empty) * @param parentNode the parent {@link Node node} (cannot be <code>null</code>) * @throws Exception if there is a problem */ protected void record(final Initializer initializer, final String nodeName, final Node parentNode) throws Exception { final Block block = initializer.getBody(); if (block != null) { @SuppressWarnings("unchecked") final List<Statement> statements = block.statements(); if ((statements != null) && !statements.isEmpty()) { final Node initializerNode = parentNode.addNode(nodeName, ClassFileSequencerLexicon.STATEMENTS); record(block, initializerNode); } } }
From source file:org.modeshape.sequencer.javafile.JdtRecorder.java
License:Apache License
/** * <pre>/*from w w w . j a v a 2 s. c o m*/ * MethodDeclaration: * [ Javadoc ] { ExtendedModifier } * [ < TypeParameter { , TypeParameter } > ] * ( Type | void ) Identifier ( * [ FormalParameter * { , FormalParameter } ] ) {[ ] } * [ throws TypeName { , TypeName } ] ( Block | ; ) * * ConstructorDeclaration: * [ Javadoc ] { ExtendedModifier } * [ < TypeParameter { , TypeParameter } > ] * Identifier ( * [ FormalParameter * { , FormalParameter } ] ) * [throws TypeName { , TypeName } ] Block * * </pre> * * @param method the {@link MethodDeclaration method} being recorded (cannot be <code>null</code>) * @param parentNode the parent {@link Node node} (cannot be <code>null</code>) * @throws Exception if there is a problem */ protected void record(final MethodDeclaration method, final Node parentNode) throws Exception { final String name = method.getName().getFullyQualifiedName(); final Node methodNode = parentNode.addNode(name, ClassFileSequencerLexicon.METHOD); methodNode.setProperty(ClassFileSequencerLexicon.NAME, name); { // javadocs final Javadoc javadoc = method.getJavadoc(); if (javadoc != null) { record(javadoc, methodNode); } } { // type parameters @SuppressWarnings("unchecked") final List<TypeParameter> typeParams = method.typeParameters(); if ((typeParams != null) && !typeParams.isEmpty()) { final Node containerNode = methodNode.addNode(ClassFileSequencerLexicon.TYPE_PARAMETERS, ClassFileSequencerLexicon.TYPE_PARAMETERS); for (final TypeParameter param : typeParams) { record(param, containerNode); } } } { // modifiers final int modifiers = method.getModifiers(); methodNode.setProperty(ClassFileSequencerLexicon.ABSTRACT, (modifiers & Modifier.ABSTRACT) != 0); methodNode.setProperty(ClassFileSequencerLexicon.FINAL, (modifiers & Modifier.FINAL) != 0); methodNode.setProperty(ClassFileSequencerLexicon.NATIVE, (modifiers & Modifier.NATIVE) != 0); methodNode.setProperty(ClassFileSequencerLexicon.STATIC, (modifiers & Modifier.STATIC) != 0); methodNode.setProperty(ClassFileSequencerLexicon.STRICT_FP, (modifiers & Modifier.STRICTFP) != 0); methodNode.setProperty(ClassFileSequencerLexicon.SYNCHRONIZED, (modifiers & Modifier.SYNCHRONIZED) != 0); methodNode.setProperty(ClassFileSequencerLexicon.VISIBILITY, getVisibility(modifiers)); } { // annotations @SuppressWarnings("unchecked") final List<IExtendedModifier> modifiers = method.modifiers(); recordAnnotations(modifiers, methodNode); } { // parameters @SuppressWarnings("unchecked") final List<SingleVariableDeclaration> params = method.parameters(); if ((params != null) && !params.isEmpty()) { final Node containerNode = methodNode.addNode(ClassFileSequencerLexicon.METHOD_PARAMETERS, ClassFileSequencerLexicon.PARAMETERS); for (final SingleVariableDeclaration param : params) { record(param, containerNode); } } } { // return type if (method.isConstructor()) { methodNode.setProperty(ClassFileSequencerLexicon.RETURN_TYPE_CLASS_NAME, Void.TYPE.getCanonicalName()); } else { final Type returnType = method.getReturnType2(); methodNode.setProperty(ClassFileSequencerLexicon.RETURN_TYPE_CLASS_NAME, getTypeName(returnType)); record(returnType, ClassFileSequencerLexicon.RETURN_TYPE, methodNode); } } { // thrown exceptions @SuppressWarnings("unchecked") final List<Name> errors = method.thrownExceptions(); if ((errors != null) && !errors.isEmpty()) { final String[] errorNames = new String[errors.size()]; int i = 0; for (final Name error : errors) { errorNames[i++] = error.getFullyQualifiedName(); } methodNode.setProperty(ClassFileSequencerLexicon.THROWN_EXCEPTIONS, errorNames); } } { // body final Block body = method.getBody(); if ((body != null) && (body.statements() != null) && !body.statements().isEmpty()) { final Node bodyNode = methodNode.addNode(ClassFileSequencerLexicon.BODY, ClassFileSequencerLexicon.STATEMENTS); record(body, bodyNode); } } recordSourceReference(method, methodNode); }
From source file:org.mpi.vasco.sieve.staticanalysis.templatecreator.DatabaseRecordClassCreator.java
License:Open Source License
/** * Creates the update field function, the field is not lww. * * @param df the df// ww w .jav a2 s . co m * @return the method declaration */ private MethodDeclaration createUpdateFieldFunction(DataField df) { if (CrdtFactory.isNormalDataType(df.get_Crdt_Data_Type())) { return null; } String requireSpecs = JahobSpecsUtil.requirePrefix; String modifySpecs = JahobSpecsUtil.modifyPrefix; String ensureSpecs = JahobSpecsUtil.ensurePrefix; String methodName = "update" + df.get_Data_Field_Name(); MethodDeclaration methodDeclaration = super.createMethodDeclaration(PrimitiveType.VOID, methodName, ModifierKeyword.PUBLIC_KEYWORD); //set parameter String crdtFieldType = CrdtFactory.getProperCrdtObject(df.get_Crdt_Data_Type(), df.get_Data_Type()); String argName = "arg0"; SingleVariableDeclaration varDecl = super.createVariableDeclaration(crdtFieldType, argName, false); methodDeclaration.parameters().add(varDecl); org.eclipse.jdt.core.dom.Block block = super.getASTNode().newBlock(); MethodInvocation methodInvocation = super.getASTNode().newMethodInvocation(); //get this expression FieldAccess fieldA = super.getASTNode().newFieldAccess(); fieldA.setExpression(super.getASTNode().newThisExpression()); fieldA.setName(super.getASTNode().newSimpleName(df.get_Data_Field_Name_Escape_Jahob())); methodInvocation.setExpression(fieldA); methodInvocation.setName(super.getASTNode().newSimpleName("update")); MethodInvocation innerMethodInvocation = super.getASTNode().newMethodInvocation(); innerMethodInvocation.setExpression(super.getASTNode().newSimpleName(argName)); innerMethodInvocation.setName(super.getASTNode().newSimpleName("getDelta")); methodInvocation.arguments().add(innerMethodInvocation); ExpressionStatement expressionStatement = super.getASTNode().newExpressionStatement(methodInvocation); block.statements().add(expressionStatement); List<String> specs = new ArrayList<String>(); requireSpecs += JahobSpecsUtil.getRequireNotNullClause(argName); requireSpecs += " & " + JahobSpecsUtil.getRequireNotNullClause( JahobSpecsUtil.getJahobRecordField(this.getClassName(), df.get_Data_Field_Name())) + "\""; specs.add(requireSpecs); modifySpecs += JahobSpecsUtil.getModifyField(df.get_Crdt_Data_Type()); specs.add(modifySpecs); ensureSpecs += JahobSpecsUtil.getEnsureClauseForNumberDelta(this.getClassName(), df, argName) + "\""; specs.add(ensureSpecs); this.methodSpecs.put(methodName, specs); methodDeclaration.setBody(block); return methodDeclaration; }
From source file:org.mpi.vasco.sieve.staticanalysis.templatecreator.DatabaseRecordClassCreator.java
License:Open Source License
/** * Creates the update field function, the field is lww. * * @param df the df/*from w w w. java 2 s .c o m*/ * @param lwwLogicTsDf the lww logic ts df * @return the method declaration */ private MethodDeclaration createUpdateFieldFunction(DataField df, DataField lwwLogicTsDf) { String methodName = "update" + df.get_Data_Field_Name(); MethodDeclaration methodDeclaration = super.createMethodDeclaration(PrimitiveType.VOID, methodName, ModifierKeyword.PUBLIC_KEYWORD); //set parameter String fieldArgName = "arg0"; String lwwtsArgName = "arg1"; String crdtFieldType = CrdtFactory.getProperCrdtObject(df.get_Crdt_Data_Type(), df.get_Data_Type()); if (!CrdtFactory.isLwwDeletedFlag(df.get_Crdt_Data_Type())) { SingleVariableDeclaration varDecl = super.createVariableDeclaration(crdtFieldType, fieldArgName, false); methodDeclaration.parameters().add(varDecl); } //if lww then put lww timestamp String lwwLogicalTsCrdtFieldType = CrdtFactory.getProperCrdtObject(lwwLogicTsDf.get_Crdt_Data_Type(), lwwLogicTsDf.get_Data_Type()); SingleVariableDeclaration lwwLogicalTsVarDecl = super.createVariableDeclaration(lwwLogicalTsCrdtFieldType, lwwtsArgName, false); methodDeclaration.parameters().add(lwwLogicalTsVarDecl); org.eclipse.jdt.core.dom.Block block = super.getASTNode().newBlock(); MethodInvocation methodInvocation = super.getASTNode().newMethodInvocation(); //get this expression FieldAccess fieldA = super.getASTNode().newFieldAccess(); fieldA.setExpression(super.getASTNode().newThisExpression()); fieldA.setName(super.getASTNode().newSimpleName(df.get_Data_Field_Name_Escape_Jahob())); methodInvocation.setExpression(fieldA); methodInvocation.setName(super.getASTNode().newSimpleName("update")); if (CrdtFactory.isLwwDeletedFlag(df.get_Crdt_Data_Type())) { NumberLiteral numLit = super.getASTNode().newNumberLiteral("1"); methodInvocation.arguments().add(numLit); } else { MethodInvocation innerMethodInvocation = super.getASTNode().newMethodInvocation(); innerMethodInvocation.setExpression(super.getASTNode().newSimpleName(fieldArgName)); innerMethodInvocation.setName(super.getASTNode().newSimpleName("getValue")); methodInvocation.arguments().add(innerMethodInvocation); } methodInvocation.arguments().add(super.getASTNode().newSimpleName(lwwtsArgName)); ExpressionStatement expressionStatement = super.getASTNode().newExpressionStatement(methodInvocation); block.statements().add(expressionStatement); methodDeclaration.setBody(block); String requireSpecs = JahobSpecsUtil.requirePrefix; String modifySpecs = JahobSpecsUtil.modifyPrefix; String ensureSpecs = JahobSpecsUtil.ensurePrefix; List<String> specs = new ArrayList<String>(); if (CrdtFactory.isLwwDeletedFlag(df.get_Crdt_Data_Type())) { requireSpecs += JahobSpecsUtil.getRequireNotNullClause( JahobSpecsUtil.getJahobRecordField(this.getClassName(), df.get_Data_Field_Name())); requireSpecs += "&" + JahobSpecsUtil .getRequireNotNullClause(JahobSpecsUtil.getJahobRecordFieldLts(this.getClassName(), df)); requireSpecs += " & " + JahobSpecsUtil.getRequireNotNullClause(lwwtsArgName) + "\""; ensureSpecs += JahobSpecsUtil.getEnsureClauseForLwwDeletedFlag(this.getClassName(), df, lwwLogicTsDf, lwwtsArgName, "1") + "\""; } else { requireSpecs += JahobSpecsUtil.getRequireNotNullClause(fieldArgName); requireSpecs += " & " + JahobSpecsUtil.getRequireNotNullClause( JahobSpecsUtil.getJahobRecordField(this.getClassName(), df.get_Data_Field_Name())); requireSpecs += "& " + JahobSpecsUtil .getRequireNotNullClause(JahobSpecsUtil.getJahobRecordFieldLts(this.getClassName(), df)); requireSpecs += " & " + JahobSpecsUtil.getRequireNotNullClause(lwwtsArgName) + "\""; ensureSpecs += JahobSpecsUtil.getEnsureClauseForLww(this.getClassName(), df, fieldArgName, lwwLogicTsDf, lwwtsArgName) + "\""; } modifySpecs += JahobSpecsUtil.getModifyField(df.get_Crdt_Data_Type()); specs.add(requireSpecs); specs.add(modifySpecs); specs.add(ensureSpecs); this.methodSpecs.put(methodName, specs); return methodDeclaration; }
From source file:org.mpi.vasco.sieve.staticanalysis.templatecreator.DatabaseRecordClassCreator.java
License:Open Source License
private MethodDeclaration createUndeleteFieldFunction(DataField df, DataField lwwLogicTsDf) { String methodName = "undelete" + df.get_Data_Field_Name(); MethodDeclaration methodDeclaration = super.createMethodDeclaration(PrimitiveType.VOID, methodName, ModifierKeyword.PUBLIC_KEYWORD); //set parameter String lwwtsArgName = "arg0"; //if lww then put lww timestamp String lwwLogicalTsCrdtFieldType = CrdtFactory.getProperCrdtObject(lwwLogicTsDf.get_Crdt_Data_Type(), lwwLogicTsDf.get_Data_Type()); SingleVariableDeclaration lwwLogicalTsVarDecl = super.createVariableDeclaration(lwwLogicalTsCrdtFieldType, lwwtsArgName, false);//from ww w . j av a 2s . co m methodDeclaration.parameters().add(lwwLogicalTsVarDecl); org.eclipse.jdt.core.dom.Block block = super.getASTNode().newBlock(); MethodInvocation methodInvocation = super.getASTNode().newMethodInvocation(); //get this expression FieldAccess fieldA = super.getASTNode().newFieldAccess(); fieldA.setExpression(super.getASTNode().newThisExpression()); fieldA.setName(super.getASTNode().newSimpleName(df.get_Data_Field_Name_Escape_Jahob())); methodInvocation.setExpression(fieldA); methodInvocation.setName(super.getASTNode().newSimpleName("update")); NumberLiteral numLit = super.getASTNode().newNumberLiteral("0"); methodInvocation.arguments().add(numLit); methodInvocation.arguments().add(super.getASTNode().newSimpleName(lwwtsArgName)); ExpressionStatement expressionStatement = super.getASTNode().newExpressionStatement(methodInvocation); block.statements().add(expressionStatement); methodDeclaration.setBody(block); String requireSpecs = JahobSpecsUtil.requirePrefix; String modifySpecs = JahobSpecsUtil.modifyPrefix; String ensureSpecs = JahobSpecsUtil.ensurePrefix; List<String> specs = new ArrayList<String>(); requireSpecs += JahobSpecsUtil.getRequireNotNullClause( JahobSpecsUtil.getJahobRecordField(this.getClassName(), df.get_Data_Field_Name())); requireSpecs += "&" + JahobSpecsUtil .getRequireNotNullClause(JahobSpecsUtil.getJahobRecordFieldLts(this.getClassName(), df)); requireSpecs += " & " + JahobSpecsUtil.getRequireNotNullClause(lwwtsArgName) + "\""; ensureSpecs += JahobSpecsUtil.getEnsureClauseForLwwDeletedFlag(this.getClassName(), df, lwwLogicTsDf, lwwtsArgName, "0") + "\""; modifySpecs += JahobSpecsUtil.getModifyField(df.get_Crdt_Data_Type()); specs.add(requireSpecs); specs.add(modifySpecs); specs.add(ensureSpecs); this.methodSpecs.put(methodName, specs); return methodDeclaration; }
From source file:org.mpi.vasco.sieve.staticanalysis.templatecreator.DatabaseRecordClassCreator.java
License:Open Source License
/** * Creates the update lww logical timestamp function. * * @param df the df/*from w ww. j a v a 2 s .c om*/ * @return the method declaration */ public MethodDeclaration createUpdateLwwLogicalTimestampFunction(DataField df) { String methodName = "update" + df.get_Data_Field_Name(); MethodDeclaration methodDeclaration = super.createMethodDeclaration(PrimitiveType.VOID, methodName, ModifierKeyword.PUBLIC_KEYWORD); String argName = "arg0"; //set parameter String crdtFieldType = CrdtFactory.getProperCrdtObject(df.get_Crdt_Data_Type(), df.get_Data_Type()); SingleVariableDeclaration varDecl = super.createVariableDeclaration(crdtFieldType, argName, false); methodDeclaration.parameters().add(varDecl); org.eclipse.jdt.core.dom.Block block = super.getASTNode().newBlock(); MethodInvocation methodInvocation = super.getASTNode().newMethodInvocation(); //get this expression FieldAccess fieldA = super.getASTNode().newFieldAccess(); fieldA.setExpression(super.getASTNode().newThisExpression()); fieldA.setName(super.getASTNode().newSimpleName(df.get_Data_Field_Name())); methodInvocation.setExpression(fieldA); methodInvocation.setName(super.getASTNode().newSimpleName("updateComp")); //get value of the lww logicaltimestamp MethodInvocation innerMethodInvocation = super.getASTNode().newMethodInvocation(); innerMethodInvocation.setExpression(super.getASTNode().newSimpleName(argName)); innerMethodInvocation.setName(super.getASTNode().newSimpleName("getValue")); methodInvocation.arguments().add(innerMethodInvocation); ExpressionStatement expressionStatement = super.getASTNode().newExpressionStatement(methodInvocation); block.statements().add(expressionStatement); methodDeclaration.setBody(block); String requireSpecs = JahobSpecsUtil.requirePrefix; String modifySpecs = JahobSpecsUtil.modifyPrefix; String ensureSpecs = JahobSpecsUtil.ensurePrefix; List<String> specs = new ArrayList<String>(); requireSpecs += JahobSpecsUtil.getRequireNotNullClause(argName); requireSpecs += " & " + JahobSpecsUtil.getRequireNotNullClause( JahobSpecsUtil.getJahobRecordField(this.getClassName(), df.get_Data_Field_Name())) + "\""; specs.add(requireSpecs); modifySpecs += JahobSpecsUtil.getModifyField(df.get_Crdt_Data_Type()); specs.add(modifySpecs); ensureSpecs += JahobSpecsUtil.getEnsureClauseForLwwLogicalTimestamp(this.getClassName(), df, argName) + "\""; specs.add(ensureSpecs); this.methodSpecs.put(methodName, specs); return methodDeclaration; }
From source file:org.mpi.vasco.sieve.staticanalysis.templatecreator.DatabaseRecordClassCreator.java
License:Open Source License
/** * Creates the get field function.// w w w. j a va 2 s . c o m * * @param df the df * @return the method declaration */ private MethodDeclaration createGetFieldFunction(DataField df) { String methodName = "get" + df.get_Data_Field_Name(); String returnType = CrdtFactory.getProperCrdtObject(df.get_Crdt_Data_Type(), df.get_Data_Type()); MethodDeclaration methodDeclaration = super.createMethodDeclaration(returnType, methodName, ModifierKeyword.PUBLIC_KEYWORD); String methodSpecs = JahobSpecsUtil.ensurePrefix; methodSpecs += " result = " + this.getClassName() + "_" + df.get_Data_Field_Name() + "\""; // add the method body here org.eclipse.jdt.core.dom.Block block = super.getASTNode().newBlock(); ReturnStatement returnStmt = super.getASTNode().newReturnStatement(); FieldAccess fieldA = super.getASTNode().newFieldAccess(); fieldA.setExpression(super.getASTNode().newThisExpression()); fieldA.setName(super.getASTNode().newSimpleName(df.get_Data_Field_Name_Escape_Jahob())); returnStmt.setExpression(fieldA); block.statements().add(returnStmt); methodDeclaration.setBody(block); List<String> specs = new ArrayList<String>(); specs.add(methodSpecs); this.methodSpecs.put(methodName, specs); return methodDeclaration; }
From source file:org.mpi.vasco.sieve.staticanalysis.templatecreator.DatabaseRecordClassCreator.java
License:Open Source License
/** * Creates the constructor declaration./* w ww . ja va 2s. c o m*/ * * @return the method declaration * @see staticanalysis.templatecreator.SourceCodeGenerator#createConstructorDeclaration() */ @Override public MethodDeclaration createConstructorDeclaration() { MethodDeclaration methodDeclaration = super.createMethodDeclaration(PrimitiveType.VOID, this.getClassName(), ModifierKeyword.PUBLIC_KEYWORD); methodDeclaration.setConstructor(true); List<String> specs = new ArrayList<String>(); String modifySpecs = JahobSpecsUtil.modifyPrefix; String ensureSpecs = JahobSpecsUtil.ensurePrefix; // set parameters for (int i = 0; i < this.fieldList.size(); i++) { DataField df = this.fieldList.get(i); String argName = "arg" + i; //create a variable and set this as a parameter String crdtImplTypeString = CrdtFactory.getProperCrdtObject(df.get_Crdt_Data_Type(), df.get_Data_Type()); SingleVariableDeclaration varDecl = super.createVariableDeclaration(crdtImplTypeString, argName, false); methodDeclaration.parameters().add(varDecl); modifySpecs += JahobSpecsUtil.getModifyField(this.getClassName(), df.get_Data_Field_Name()) + ","; ensureSpecs += JahobSpecsUtil.getEnsureFieldEqual(this.getClassName(), df.get_Data_Field_Name(), argName) + " & "; } modifySpecs = StringOperations.removeLastComma(modifySpecs); ensureSpecs = StringOperations.replaceLastMathAndWithDoubleQuotes(ensureSpecs); // here please add all parameters assignment org.eclipse.jdt.core.dom.Block block = super.getASTNode().newBlock(); for (int i = 0; i < this.fieldList.size(); i++) { DataField df = this.fieldList.get(i); String argName = "arg" + i; // add assignment for the parameter Assignment assignExpr = super.getASTNode().newAssignment(); assignExpr.setOperator(Assignment.Operator.ASSIGN); FieldAccess leftOpr = super.getASTNode().newFieldAccess(); leftOpr.setExpression(super.getASTNode().newThisExpression()); leftOpr.setName(super.getASTNode().newSimpleName(df.get_Data_Field_Name())); assignExpr.setLeftHandSide(leftOpr); assignExpr.setRightHandSide(super.getASTNode().newSimpleName(argName)); Statement assignStmt = super.getASTNode().newExpressionStatement(assignExpr); block.statements().add(assignStmt); } methodDeclaration.setBody(block); specs.add(modifySpecs); specs.add(ensureSpecs); this.methodSpecs.put(this.getClassName(), specs); return methodDeclaration; }
From source file:org.mpi.vasco.sieve.staticanalysis.templatecreator.DatabaseTableClassCreator.java
License:Open Source License
/** * Creates the get size function./*from w w w .ja v a 2 s .co m*/ * * @return the method declaration */ public MethodDeclaration createGetSizeFunction() { String methodName = "getSize"; MethodDeclaration methodDeclaration = super.createMethodDeclaration(PrimitiveType.INT, methodName, ModifierKeyword.PUBLIC_KEYWORD); org.eclipse.jdt.core.dom.Block block = super.getASTNode().newBlock(); ReturnStatement returnStmt = super.getASTNode().newReturnStatement(); FieldAccess fieldA = super.getASTNode().newFieldAccess(); fieldA.setExpression(super.getASTNode().newThisExpression()); fieldA.setName(super.getASTNode().newSimpleName("size")); returnStmt.setExpression(fieldA); block.statements().add(returnStmt); methodDeclaration.setBody(block); String requireSpecs = JahobSpecsUtil.requirePrefix; String ensureSpecs = JahobSpecsUtil.ensurePrefix; List<String> specs = new ArrayList<String>(); requireSpecs += JahobSpecsUtil.getTableNotInit(this.getClassName()) + "\""; ensureSpecs += JahobSpecsUtil.getSizeEqualResult(this.getClassName()) + "\""; specs.add(requireSpecs); specs.add(ensureSpecs); this.methodSpecs.put(methodName, specs); return methodDeclaration; }
From source file:org.mpi.vasco.sieve.staticanalysis.templatecreator.DatabaseTableClassCreator.java
License:Open Source License
/** * Creates the is contained function./*from ww w . ja va 2 s.c o m*/ * * @return the method declaration */ public MethodDeclaration createIsContainedFunction() { String methodName = "isContained"; MethodDeclaration methodDeclaration = super.createMethodDeclaration(PrimitiveType.BOOLEAN, methodName, ModifierKeyword.PUBLIC_KEYWORD); String recordName = tableInstance.get_Table_Name() + DatabaseRecordClassCreator.RECORDSTRING; SingleVariableDeclaration varDecl = super.createVariableDeclaration(recordName, recordName.toLowerCase(), false); methodDeclaration.parameters().add(varDecl); org.eclipse.jdt.core.dom.Block block = super.getASTNode().newBlock(); //add the index variable String indexVar = "i"; VariableDeclarationStatement varDeclStmt = super.createVariableDeclarationStatement(PrimitiveType.INT, indexVar, false, null); block.statements().add(varDeclStmt); //put a for loop here ForStatement forStmt = super.getASTNode().newForStatement(); //set initializer Assignment assignExpr = super.getASTNode().newAssignment(); assignExpr.setOperator(Assignment.Operator.ASSIGN); assignExpr.setLeftHandSide(super.getASTNode().newSimpleName(indexVar)); NumberLiteral initializedValue = super.getASTNode().newNumberLiteral("0"); assignExpr.setRightHandSide(initializedValue); forStmt.initializers().add(assignExpr); //set condition expression InfixExpression infixExpr = super.getASTNode().newInfixExpression(); infixExpr.setOperator(InfixExpression.Operator.LESS); infixExpr.setLeftOperand(super.getASTNode().newSimpleName(indexVar)); FieldAccess fieldA = super.getASTNode().newFieldAccess(); fieldA.setExpression(super.getASTNode().newThisExpression()); fieldA.setName(super.getASTNode().newSimpleName("size")); infixExpr.setRightOperand(fieldA); forStmt.setExpression(infixExpr); //set update PostfixExpression updateExpr = super.getASTNode().newPostfixExpression(); updateExpr.setOperator(PostfixExpression.Operator.INCREMENT); updateExpr.setOperand(super.getASTNode().newSimpleName(indexVar)); forStmt.updaters().add(updateExpr); //set for loop body org.eclipse.jdt.core.dom.Block forLoopBlock = super.getASTNode().newBlock(); //add a if statement IfStatement ifStmt = super.getASTNode().newIfStatement(); //set if condition InfixExpression ifCondExp = super.getASTNode().newInfixExpression(); //left expr is in the form: this.table[i] ArrayAccess arrayA = super.getASTNode().newArrayAccess(); FieldAccess tableFieldA = super.getASTNode().newFieldAccess(); tableFieldA.setExpression(super.getASTNode().newThisExpression()); tableFieldA.setName(super.getASTNode().newSimpleName("table")); arrayA.setArray(tableFieldA); arrayA.setIndex(super.getASTNode().newSimpleName(indexVar)); ifCondExp.setLeftOperand(arrayA); //equal operator ifCondExp.setOperator(InfixExpression.Operator.EQUALS); //right expr ifCondExp.setRightOperand(super.getASTNode().newSimpleName(recordName.toLowerCase())); ifStmt.setExpression(ifCondExp); //add block for ifStmt org.eclipse.jdt.core.dom.Block ifBlock = super.getASTNode().newBlock(); ReturnStatement trueReturnStmt = super.getASTNode().newReturnStatement(); BooleanLiteral trueValue = super.getASTNode().newBooleanLiteral(true); trueReturnStmt.setExpression(trueValue); ifBlock.statements().add(trueReturnStmt); ifStmt.setThenStatement(ifBlock); forLoopBlock.statements().add(ifStmt); forStmt.setBody(forLoopBlock); block.statements().add(forStmt); //return false ReturnStatement falseReturnStmt = super.getASTNode().newReturnStatement(); BooleanLiteral falseValue = super.getASTNode().newBooleanLiteral(false); falseReturnStmt.setExpression(falseValue); block.statements().add(falseReturnStmt); methodDeclaration.setBody(block); return methodDeclaration; }