<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hello,<div><br></div><div>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().&nbsp;</div><div>When digging into the code, I found that my problem is in the following method of&nbsp;<span style="font-family: 'Source Code Pro'; font-size: 11px;">org.jboss.tools.common.refactoring.MarkerResolutionUtils:</span></div><div><br></div><div><br></div><div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro'; color: rgb(119, 119, 119);"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>@SuppressWarnings<span style="color: #000000">(</span><span style="color: #3933ff">"unchecked"</span><span style="color: #000000">)</span></div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #931a68"><b>public</b></span> <span style="color: #931a68"><b>static</b></span> &lt;T <span style="color: #931a68"><b>extends</b></span> IJavaElement&gt; T findWorkingCopy(ICompilationUnit <span style="color: #7e504f">compilationUnit</span>, T <span style="color: #7e504f">element</span>) <span style="color: #931a68"><b>throws</b></span> JavaModelException{</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                </span><span style="color: #931a68"><b>if</b></span>(<span style="color: #7e504f">element</span> <span style="color: #931a68"><b>instanceof</b></span> IAnnotation){</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                        </span>IJavaElement <span style="color: #7e504f">parent</span> = findWorkingCopy(<span style="color: #7e504f">compilationUnit</span>, <span style="color: #7e504f">element</span>.getParent());</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                        </span><span style="color: #931a68"><b>if</b></span>(<span style="color: #7e504f">parent</span> <span style="color: #931a68"><b>instanceof</b></span> IAnnotatable){</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                                </span><span style="color: #931a68"><b>for</b></span>(IAnnotation <span style="color: #7e504f">a</span> : ((IAnnotatable)<span style="color: #7e504f">parent</span>).getAnnotations()){</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                                        </span><span style="color: #931a68"><b>if</b></span>(<span style="color: #7e504f">a</span>.getElementName().equals(<span style="color: #7e504f">element</span>.getElementName()))</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                                                </span><span style="color: #931a68"><b>return</b></span> (T)<span style="color: #7e504f">a</span>;</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                                </span>}</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                        </span>}</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                </span>}<span style="color: #931a68"><b>else</b></span> <span style="color: #931a68"><b>if</b></span>(<span style="color: #7e504f">element</span> <span style="color: #931a68"><b>instanceof</b></span> ILocalVariable &amp;&amp; ((ILocalVariable) <span style="color: #7e504f">element</span>).isParameter()){</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                        </span>IJavaElement <span style="color: #7e504f">parent</span> = findWorkingCopy(<span style="color: #7e504f">compilationUnit</span>, <span style="color: #7e504f">element</span>.getParent());</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                        </span><span style="color: #931a68"><b>if</b></span>(<span style="color: #7e504f">parent</span> <span style="color: #931a68"><b>instanceof</b></span> IMethod){</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                                </span><span style="color: #931a68"><b>for</b></span>(ILocalVariable <span style="color: #7e504f">parameter</span> : ((IMethod)<span style="color: #7e504f">parent</span>).getParameters()){</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                                        </span><span style="color: #931a68"><b>if</b></span>(<span style="color: #7e504f">parameter</span>.getElementName().equals(<span style="color: #7e504f">element</span>.getElementName()) &amp;&amp; <span style="color: #7e504f">parameter</span>.getTypeSignature().equals(((ILocalVariable)<span style="color: #7e504f">element</span>).getTypeSignature()))</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                                                </span><span style="color: #931a68"><b>return</b></span> (T)<span style="color: #7e504f">parameter</span>;</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                                </span>}</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                        </span>}</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                </span>}<span style="color: #931a68"><b>else</b></span>{</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                        </span>IJavaElement[] <span style="color: #7e504f">elements</span> = <span style="color: #7e504f">compilationUnit</span>.findElements(<span style="color: #7e504f">element</span>);</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                        </span><span style="color: #931a68"><b>if</b></span>(<span style="color: #7e504f">elements</span> != <span style="color: #931a68"><b>null</b></span>){</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                                </span><span style="color: #931a68"><b>for</b></span>(IJavaElement <span style="color: #7e504f">e</span> : <span style="color: #7e504f">elements</span>){</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                                        </span><span style="color: #931a68"><b>if</b></span>(<span style="color: #7e504f">e</span>.getClass().equals(<span style="color: #7e504f">element</span>.getClass()))</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                                                </span><span style="color: #931a68"><b>return</b></span> (T)<span style="color: #7e504f">e</span>;</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                                </span>}</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                        </span>}</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro'; color: rgb(147, 26, 104);"><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">                </span></span><b>return</b><span style="color: #000000"> </span><b>null</b><span style="color: #000000">;</span></div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><br></div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><br></div><div style="margin: 0px; font-size: 11px; font-family: 'Source Code Pro';"><br></div><div apple-content-edited="true">
<span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px;"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">In the code above, the last if/else block checks if&nbsp;<span style="font-family: 'Source Code Pro'; font-size: 11px; orphans: auto; widows: auto; color: rgb(126, 80, 79);">e</span><span style="font-family: 'Source Code Pro'; font-size: 11px; orphans: auto; widows: auto;">.getClass().equals(</span><span style="font-family: 'Source Code Pro'; font-size: 11px; orphans: auto; widows: auto; color: rgb(126, 80, 79);">element</span><span style="font-family: 'Source Code Pro'; font-size: 11px; orphans: auto; widows: auto;">.getClass())</span>, which does not work in my case because I have&nbsp;<span style="font-family: 'Source Code Pro'; font-size: 11px; text-align: -webkit-auto;">org.eclipse.jdt.internal.core.SourceType</span><span style="text-align: -webkit-auto;"> vs&nbsp;</span><span style="font-family: 'Source Code Pro'; font-size: 11px; text-align: -webkit-auto;">org.eclipse.jdt.internal.core.ResolvedSourceType</span><span style="text-align: -webkit-auto;">. 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.</span></div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">For example, in my unit tests, it would be:&nbsp;<span style="font-family: 'Source Code Pro'; font-size: 11px; text-align: -webkit-auto;">=org.jboss.tools.ws.jaxrs.tests.sampleproject/src\/main\/java&lt;org.jboss.tools.ws.jaxrs.sample.services{BAZ.java[BAZ</span><span style="text-align: -webkit-auto;"> in both cases ;-)</span></div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><span style="text-align: -webkit-auto;">WDYT ?&nbsp;</span></div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><span style="text-align: -webkit-auto;"><br></span></div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><span style="text-align: -webkit-auto;">If the change I suggest makes sense, I'll be more than happy to open a JIRA and attach a PR to it ;-)</span></div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><span style="text-align: -webkit-auto;"><br></span></div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><span style="text-align: -webkit-auto;">Thanks.&nbsp;</span></div><div style="font-family: Helvetica; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br></div><div style="font-family: Helvetica; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Best regards,</div><div style="font-family: Helvetica; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">/Xavier<br><br><br></div></span></span>
</div>
<br></div></body></html>