[jbosstools-dev] Question about org.jboss.tools.common.refactoring.MarkerResolutionUtils

Alexey Kazakov akazakov at exadel.com
Thu Jun 26 17:27:33 EDT 2014


Hi,

Yes, it makes sense. Please go ahead and open a JIRA with your PR.

On 06/26/2014 09:22 AM, Xavier Coulon wrote:
> 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.SourceTypevs 
> 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[BAZin 
> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jbosstools-dev/attachments/20140626/1baa7437/attachment.html 


More information about the jbosstools-dev mailing list