| Summary: | Using DOM API a function can not be inserted in the last position of object literal | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [WebTools] JSDT | Reporter: | Chris Jaun <cmjaun> | ||||
| Component: | General | Assignee: | Chris Jaun <cmjaun> | ||||
| Status: | RESOLVED FIXED | QA Contact: | Nitin Dahyabhai <thatnitind> | ||||
| Severity: | normal | ||||||
| Priority: | P3 | Flags: | thatnitind:
review+
|
||||
| Version: | 3.2 | ||||||
| Target Milestone: | 3.2.1 | ||||||
| Hardware: | PC | ||||||
| OS: | Windows XP | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
Created attachment 173111 [details]
patch
Patch uses the declaration start and end to calculate length of function.
Patch allows below junit to pass and correctly inserts fields into the final position of object literals. Patch checked in. |
Below is the test case I am using to test... /** * insert a new function in an object literal */ public void xtest0009() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test0009", false, null); StringBuffer buf= new StringBuffer(); buf.append("var o = {\n"); buf.append("con : function(args){},\n"); buf.append("fun1 : function(args){}\n"); buf.append("};\n"); IJavaScriptUnit cu= pack1.createCompilationUnit("X.js", buf.toString(), false, null); JavaScriptUnit astRoot= createCU(cu, false); astRoot.recordModifications(); AST a = astRoot.getAST(); List statements = astRoot.statements(); VariableDeclarationStatement varDeclaration = (VariableDeclarationStatement)statements.get(0); VariableDeclarationFragment frag = (VariableDeclarationFragment) varDeclaration.fragments().get(0); ObjectLiteral obLit = (ObjectLiteral) frag.getInitializer(); List fields = obLit.fields(); ObjectLiteralField newObjectLiteralField = a.newObjectLiteralField(); newObjectLiteralField.setFieldName(a.newSimpleName("newMethod")); newObjectLiteralField.setInitializer(a.newFunctionExpression()); fields.add(newObjectLiteralField); String preview = evaluateRewrite(cu, astRoot); buf= new StringBuffer(); buf.append("var o = {\n"); buf.append("con : function(args){},\n"); buf.append("fun1 : function(args){},\n"); buf.append("newMethod : function(){}\n"); buf.append("};\n"); assertEqualString(preview, buf.toString()); } This currently fails.