Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 322331 - [introduce parameter] IntroduceParameterRefactoring wrong assurance ICompilationUnit => IMethod
Summary: [introduce parameter] IntroduceParameterRefactoring wrong assurance ICompilat...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 3.7 M2   Edit
Assignee: Dani Megert CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-11 06:17 EDT by Sergo CLA
Modified: 2010-09-15 01:57 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sergo CLA 2010-08-11 06:17:54 EDT
Build Identifier: M20090917-0800

I'm trying to create a refactoring using RefactoringDescriptor class. I'm generate the necessary arguments of the argument Map<String, String> to get an instance of the class "RefactoringDescriptor". Then a create refactoring object, that already parametrezed. Here I land in the method "private RefactoringStatus initialize(JavaRefactoringArguments arguments)„ of the class org.eclipse.jdt.internal.corext.refactoring.code.IntroduceParameterRefactoring. In this method, at line 564 is the wrong test, see Source:

if (element == null | |! element.exists () | | element.getElementType ()! = IJavaElement.COMPILATION_UNIT)
JavaRefactoringDescriptorUtil.createInputFatalStatus return (element getName (), IJavaRefactorings.INTRODUCE_PARAMETER);
else
fSourceCU = ((IMethods) element). getCompilationUnit ();

In the "if" question is assured that variable is to be "element" ICompilationUnit type. Is expected, but IMethods!

Reproducible: Always

Steps to Reproduce:
1.Try to create an Refactoring using LTK API. Something like that!
2.	public Refactoring createRefactoring(String project, String description,
			String comment) throws CoreException {

		final JavaRefactoringDescriptor descriptor = (JavaRefactoringDescriptor) RefactoringCore
				.getRefactoringContribution(
						IJavaRefactorings.INTRODUCE_PARAMETER)
				.createDescriptor(IJavaRefactorings.INTRODUCE_PARAMETER,
						project, description, comment, getAttributes(), getFlags());

		Assert.isNotNull(descriptor);
		return descriptor.createRefactoring(descriptor.validateDescriptor());
	}
3.
Comment 1 Ayushman Jain CLA 2010-08-12 02:47:49 EDT
Moving to JDT/UI.
Comment 2 Dani Megert CLA 2010-08-24 03:25:19 EDT
As you notice, the refactoring takes the CU. Why don't you simply pass the CU?
Comment 3 Sergo CLA 2010-08-25 06:15:41 EDT
(In reply to comment #2)
> As you notice, the refactoring takes the CU. Why don't you simply pass the CU?

Because you get cast exceptions

see
fSourceCU = ((IMethods) element). getCompilationUnit ();
Comment 4 Dani Megert CLA 2010-08-25 06:22:35 EDT
Ah, right. I see it now.
Comment 5 Dani Megert CLA 2010-08-25 06:24:15 EDT
Fixed in IntroduceParameterRefactoring rev. 1.91.
Comment 6 Dani Megert CLA 2010-09-15 01:57:05 EDT
Verified in I20100914-0100.