[jbosstools-issues] [JBoss JIRA] (JBIDE-17708) Workaround different classnames when finding working copy for quickfix/resolution change
Vlado Pakan (JIRA)
issues at jboss.org
Fri Jul 11 03:01:27 EDT 2014
[ https://issues.jboss.org/browse/JBIDE-17708?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Vlado Pakan closed JBIDE-17708.
-------------------------------
> Workaround different classnames when finding working copy for quickfix/resolution change
> ----------------------------------------------------------------------------------------
>
> Key: JBIDE-17708
> URL: https://issues.jboss.org/browse/JBIDE-17708
> Project: Tools (JBoss Tools)
> Issue Type: Enhancement
> Components: common/jst/core
> Affects Versions: 4.2.0.Beta2
> Reporter: Xavier Coulon
> Assignee: Xavier Coulon
> Fix For: 4.2.0.Beta3
>
>
> 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:
> {code}
> @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;
> }
> {code}
> 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
--
This message was sent by Atlassian JIRA
(v6.2.6#6264)
More information about the jbosstools-issues
mailing list