Community
Participate
Working Groups
In WTP, we have code that looks like the following to create unimplemented methods &constructors. We use the OverrideMethodsAction API, which wraps the internal operation. These eopratiosn do not create imports. Problem is that we cannot access the imports created during these operations with an API method, therefore we are forced to cast to an internal type. Suggestion is to make these operation API. if (doUnimplementedMethods) { IWorkspaceRunnable operation = OverrideMethodsAction.createRunnable(unit, binding, null, -1, true); operation.run(monitor); createImports(imports, ((AddUnimplementedMethodsOperation)operation).getCreatedImports()); } if (doConstructors) { IWorkspaceRunnable operation = AddUnimplementedConstructorsAction.createRunnable(unit, binding, null, -1, true, Modifier.PUBLIC, true); operation.run(monitor); createImports(imports, ((AddUnimplementedConstructorsOperation)operation).getCreatedImports()); }
Adding david to CC
This case is only relevant when there is an exising imports manager. Actions create operation sthat apply chnages to imports by default (i.e. we cannot set it to false, ar provide our own imports manager). A work around is to temporarily delegate the imports management to JDT, and when these operations are run, create a new imports manager to continue with. See bug 156173.
Move to JDT/UI
Naci, I have a question here, I was doing similar stuff in WTP 155 based code something like this IType type = javaProject.findType(qName); ASTParser parser= ASTParser.newParser(AST.JLS3); parser.setSource(type.getCompilationUnit()); parser.setResolveBindings(true); CompilationUnit astRoot= (CompilationUnit) parser.createAST(null); AbstractTypeDeclaration decl= (AbstractTypeDeclaration) astRoot.findDeclaringNode(type.getKey()); ITypeBinding binding= decl.resolveBinding(); IWorkspaceRunnable runnable = OverrideMethodsAction.createRunnable(astRoot, binding, null, -1, true); IWorkspace workspace = ResourcesPlugin.getWorkspace(); workspace.run(runnable, new NullProgressMonitor()); However, I notice since OverrideMethodsAction.createRunnable sets save=false in the AddUnimplementedMethodsOperation constructor There is no way to save the contents of the class after the operation runs, I think this is a bug/unnecessary limitation, After the operation runs, it does not save the contents in the file so it appears as if the operation did not work. Right now the only way I can get that code to work is to have the file open in a editor, run the runnable/operation that dirties the file, and call IWorkbenchPage.saveEditor(IEditorPart, false);
By the way I opened a separate bug 196340 to document the problem I mentioned earlier.
the plan is to make AddUnimplementedMethodsOperation and AddUnimplementedConstructorsOperation API in jdt.core manipulations. With the imports, I would recommend you to commit your changes before OverrideMethodsAction.createRunnable is called, or set up a new one after. OverrideMethodsAction.createRunnable assumes that the CU it sees is the most current. If you have some changes pending this could lead to problems. The missing save when there are no editors open is an oversight. I'll fix it.
Have to move to 3.5, unfortunately.
Naci, do you still need this?
3.5 API frozen now. Please raise your voice if you would still need this.