Bug 156170 - [api] make AddUnimplementedMethodsOperation and AddUnimplementedConstructorsOperation api
Summary: [api] make AddUnimplementedMethodsOperation and AddUnimplementedConstructorsO...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: All All
: P5 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks: 156173
  Show dependency tree
 
Reported: 2006-09-05 05:14 EDT by Naci Dai CLA
Modified: 2009-03-11 07:29 EDT (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Naci Dai CLA 2006-09-05 05:14:36 EDT
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());
}
Comment 1 Naci Dai CLA 2006-09-05 05:14:56 EDT
Adding david to CC
Comment 2 Naci Dai CLA 2006-09-05 07:38:22 EDT
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.
Comment 3 Frederic Fusier CLA 2006-09-05 12:31:21 EDT
Move to JDT/UI
Comment 4 Raj Mandayam CLA 2007-07-12 11:52:47 EDT
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);

Comment 5 Raj Mandayam CLA 2007-07-12 12:12:32 EDT
By the way I opened a separate bug 196340 to document the problem I mentioned earlier.
Comment 6 Martin Aeschlimann CLA 2007-07-16 07:09:04 EDT
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.
Comment 7 Martin Aeschlimann CLA 2008-04-17 10:12:19 EDT
Have to move to 3.5, unfortunately. 
Comment 8 Markus Keller CLA 2009-01-30 08:35:41 EST
Naci, do you still need this?
Comment 9 Dani Megert CLA 2009-03-11 07:29:45 EDT
3.5 API frozen now.

Please raise your voice if you would still need this.