[jbosstools-dev] Question about org.jboss.tools.common.refactoring.MarkerResolutionUtils
Xavier Coulon
xcoulon at redhat.com
Thu Jun 26 12:22:45 EDT 2014
Hello,
I'm writing a JUnit test to verify that a quickfix for a JAX-RS problem works fine, but my test fails because the change is not applied during the call to Change#perform().
When digging into the code, I found that my problem is in the following method of org.jboss.tools.common.refactoring.MarkerResolutionUtils:
@SuppressWarnings("unchecked")
public static <T extends IJavaElement> T findWorkingCopy(ICompilationUnit compilationUnit, T element) throws JavaModelException{
if(element instanceof IAnnotation){
IJavaElement parent = findWorkingCopy(compilationUnit, element.getParent());
if(parent instanceof IAnnotatable){
for(IAnnotation a : ((IAnnotatable)parent).getAnnotations()){
if(a.getElementName().equals(element.getElementName()))
return (T)a;
}
}
}else if(element instanceof ILocalVariable && ((ILocalVariable) element).isParameter()){
IJavaElement parent = findWorkingCopy(compilationUnit, element.getParent());
if(parent instanceof IMethod){
for(ILocalVariable parameter : ((IMethod)parent).getParameters()){
if(parameter.getElementName().equals(element.getElementName()) && parameter.getTypeSignature().equals(((ILocalVariable)element).getTypeSignature()))
return (T)parameter;
}
}
}else{
IJavaElement[] elements = compilationUnit.findElements(element);
if(elements != null){
for(IJavaElement e : elements){
if(e.getClass().equals(element.getClass()))
return (T)e;
}
}
}
return null;
}
In the code above, the last if/else block checks if e.getClass().equals(element.getClass()), which does not work in my case because I have org.eclipse.jdt.internal.core.SourceType vs org.eclipse.jdt.internal.core.ResolvedSourceType. I wonder if we should not replace this part with a comparison of a comparision of getHandleIdentifier() of both elements, which would make more sense, I believe.
For example, in my unit tests, it would be: =org.jboss.tools.ws.jaxrs.tests.sampleproject/src\/main\/java<org.jboss.tools.ws.jaxrs.sample.services{BAZ.java[BAZ in both cases ;-)
WDYT ?
If the change I suggest makes sense, I'll be more than happy to open a JIRA and attach a PR to it ;-)
Thanks.
Best regards,
/Xavier
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jbosstools-dev/attachments/20140626/68fae9be/attachment-0001.html
More information about the jbosstools-dev
mailing list