[jbosstools-dev] Question about org.jboss.tools.common.refactoring.MarkerResolutionUtils
Max Rydahl Andersen
manderse at redhat.com
Fri Jun 27 10:07:55 EDT 2014
agreed that comparing just on class type does seem very
fragile/specific.
/max
> 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
>
>
>
> _______________________________________________
> jbosstools-dev mailing list
> jbosstools-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/jbosstools-dev
/max
http://about.me/maxandersen
More information about the jbosstools-dev
mailing list