Author: dazarov
Date: 2009-09-17 10:37:38 -0400 (Thu, 17 Sep 2009)
New Revision: 17634
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolutionImpl.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRefactorSearcher.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamELReferencesQueryParticipant.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4771
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolutionImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolutionImpl.java 2009-09-17
13:59:09 UTC (rev 17633)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolutionImpl.java 2009-09-17
14:37:38 UTC (rev 17634)
@@ -36,15 +36,22 @@
* @see
org.jboss.tools.common.el.core.resolver.ELResolution#findSegmentsByJavaElement(org.eclipse.jdt.core.IJavaElement)
*/
public List<ELSegment> findSegmentsByJavaElement(IJavaElement element) {
- // TODO
- return null;
+ ArrayList<ELSegment> list = new ArrayList<ELSegment>();
+ for(ELSegment segment : segments){
+ if(segment instanceof JavaMemberELSegment &&
((JavaMemberELSegment)segment).getJavaElement().equals(element))
+ list.add(segment);
+ }
+ return list;
}
/* (non-Javadoc)
* @see org.jboss.tools.common.el.core.resolver.ELResolution#findSegmentByOffset(int)
*/
- public ELSegment findSegmentByOffset(int offcet) {
- // TODO
+ public ELSegment findSegmentByOffset(int offset) {
+ for(ELSegment segment : segments){
+ if(segment.getSourceReference() != null &&
segment.getSourceReference().getStartPosition() == offset)
+ return segment;
+ }
return null;
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRefactorSearcher.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRefactorSearcher.java 2009-09-17
13:59:09 UTC (rev 17633)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRefactorSearcher.java 2009-09-17
14:37:38 UTC (rev 17634)
@@ -11,6 +11,7 @@
package org.jboss.tools.seam.internal.core.refactoring;
import java.io.IOException;
+import java.util.List;
import java.util.StringTokenizer;
import org.eclipse.core.resources.IContainer;
@@ -19,6 +20,7 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.internal.ui.text.FastJavaPartitionScanner;
import org.eclipse.jdt.ui.text.IJavaPartitions;
@@ -36,6 +38,7 @@
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
+import org.jboss.tools.common.el.core.model.ELExpression;
import org.jboss.tools.common.el.core.model.ELInstance;
import org.jboss.tools.common.el.core.model.ELInvocationExpression;
import org.jboss.tools.common.el.core.model.ELMethodInvocation;
@@ -43,6 +46,15 @@
import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
import org.jboss.tools.common.el.core.parser.ELParser;
import org.jboss.tools.common.el.core.parser.ELParserUtil;
+import org.jboss.tools.common.el.core.resolver.ELCompletionEngine;
+import org.jboss.tools.common.el.core.resolver.ELResolution;
+import org.jboss.tools.common.el.core.resolver.ELResolver;
+import org.jboss.tools.common.el.core.resolver.ELResolverFactoryManager;
+import org.jboss.tools.common.el.core.resolver.ELSegment;
+import org.jboss.tools.common.el.core.resolver.ElVarSearcher;
+import org.jboss.tools.common.el.core.resolver.JavaMemberELSegment;
+import org.jboss.tools.common.el.core.resolver.SimpleELContext;
+import org.jboss.tools.common.el.core.resolver.Var;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.seam.core.SeamCorePlugin;
@@ -66,11 +78,17 @@
protected IFile baseFile;
protected String propertyName;
+ protected IJavaElement javaElement;
public SeamRefactorSearcher(IFile baseFile, String propertyName){
this.baseFile = baseFile;
this.propertyName = propertyName;
}
+
+ public SeamRefactorSearcher(IFile baseFile, String propertyName, IJavaElement
javaElement){
+ this(baseFile, propertyName);
+ this.javaElement = javaElement;
+ }
public void findELReferences(){
if(baseFile == null)
@@ -253,10 +271,10 @@
if(expression != null){
if(expression instanceof ELPropertyInvocation){
ELPropertyInvocation pi = (ELPropertyInvocation)expression;
- match(file, offset+pi.getName().getStart(), pi.getName().getLength());
+ checkMatch(file, pi, offset+pi.getName().getStart(), pi.getName().getLength());
}else if(expression instanceof ELMethodInvocation){
ELMethodInvocation mi = (ELMethodInvocation)expression;
- match(file, offset+mi.getName().getStart(), mi.getName().getLength());
+ checkMatch(file, mi, offset+mi.getName().getStart(), mi.getName().getLength());
}
}
}
@@ -324,6 +342,13 @@
protected abstract void match(IFile file, int offset, int length);
+ private void checkMatch(IFile file, ELExpression operand, int offset, int length){
+ if(javaElement != null && operand != null)
+ resolve(file, operand, offset, length);
+ else
+ match(file, offset, length);
+ }
+
public static String getPropertyName(String methodName){
if(methodName.startsWith(GET) || methodName.startsWith(SET)){
String name = methodName.substring(3);
@@ -339,8 +364,47 @@
}
public static boolean isSetter(String methodName){
- if(methodName.startsWith(SET))
- return true;
- return false;
+ return methodName.startsWith(SET);
}
+
+ private void resolve(IFile file, ELExpression operand, int offset, int length){
+ ELResolver[] resolvers = ELResolverFactoryManager.getInstance().getResolvers(file);
+
+ for(ELResolver resolver : resolvers){
+ if(!(resolver instanceof ELCompletionEngine))
+ continue;
+
+ SimpleELContext context = new SimpleELContext();
+
+ ElVarSearcher elSearcher = new ElVarSearcher((ELCompletionEngine)resolver);
+
+ List<Var> vars = elSearcher.findAllVars(file, offset);
+
+ if(vars == null)
+ continue;
+
+ context.setVars(vars);
+ context.setResource(file);
+ context.setElResolvers(resolvers);
+
+ ELResolution resolution = resolver.resolve(context, operand);
+
+ if(resolution == null)
+ continue;
+
+ ELSegment segment = resolution.findSegmentByOffset(offset);
+
+ if(segment == null)
+ continue;
+
+ if(segment instanceof JavaMemberELSegment){
+ JavaMemberELSegment javaSegment = (JavaMemberELSegment)segment;
+ if(javaSegment.isResolved()){
+ IJavaElement segmentJavaElement = javaSegment.getJavaElement();
+ if(segmentJavaElement.equals(javaElement))
+ match(file, offset, length);
+ }
+ }
+ }
+ }
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamELReferencesQueryParticipant.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamELReferencesQueryParticipant.java 2009-09-17
13:59:09 UTC (rev 17633)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamELReferencesQueryParticipant.java 2009-09-17
14:37:38 UTC (rev 17634)
@@ -14,6 +14,7 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.ui.search.ElementQuerySpecification;
import org.eclipse.jdt.ui.search.IMatchPresentation;
@@ -49,7 +50,7 @@
IFile file = (IFile)qs.getElement().getResource();
String name = ELSearcher.getPropertyName(qs.getElement().getElementName());
- searcher = new ELSearcher(requestor, file, name);
+ searcher = new ELSearcher(requestor, qs.getElement(), file, name);
searcher.findELReferences();
}
@@ -66,8 +67,8 @@
class ELSearcher extends SeamRefactorSearcher{
ISearchRequestor requestor;
- public ELSearcher(ISearchRequestor requestor, IFile file, String name){
- super(file, name);
+ public ELSearcher(ISearchRequestor requestor, IJavaElement element, IFile file, String
name){
+ super(file, name, element);
this.requestor = requestor;
}