Author: dazarov
Date: 2012-01-06 15:43:13 -0500 (Fri, 06 Jan 2012)
New Revision: 37699
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/ELRefactorContributionFactory.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RenameMessagePropertyProcessor.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFMessageELCompletionEngine.java
trunk/jsf/tests/org.jboss.tools.jsf.test/projects/JSFKickStartOldFormat/WebContent/pages/hello.jsp
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/refactoring/ELVariableRefactoringTest.java
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/refactoring/MessagePropertyRefactoringTest.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/refactoring/RefactorSearcher.java
Log:
Ctrl+Shift+G on a java element doesn't work for complex ELs
https://issues.jboss.org/browse/JBIDE-10593
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RenameMessagePropertyProcessor.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RenameMessagePropertyProcessor.java 2012-01-06
20:19:35 UTC (rev 37698)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RenameMessagePropertyProcessor.java 2012-01-06
20:43:13 UTC (rev 37699)
@@ -29,6 +29,7 @@
import org.jboss.tools.common.el.core.ELReference;
import org.jboss.tools.common.el.core.ElCoreMessages;
import org.jboss.tools.common.el.core.model.ELExpression;
+import org.jboss.tools.common.el.core.model.ELObject;
import org.jboss.tools.common.el.core.resolver.ELCompletionEngine;
import org.jboss.tools.common.el.core.resolver.ELContext;
import org.jboss.tools.common.el.core.resolver.ELResolution;
@@ -201,6 +202,25 @@
match(file, offset+segment.getSourceReference().getStartPosition(),
segment.getSourceReference().getLength());
}
}
+ for(ELObject child : operand.getChildren()){
+ if(child instanceof ELExpression){
+ for (ELResolver resolver : resolvers) {
+ if (!(resolver instanceof ELCompletionEngine))
+ continue;
+
+ ELResolution resolution = resolver.resolve(context, (ELExpression)child,
offset);
+
+ if(resolution == null)
+ continue;
+
+ List<ELSegment> segments =
resolution.findSegmentsByMessageProperty(segment.getBaseName(), propertyName);
+
+ for(ELSegment segment : segments){
+ match(file, offset+segment.getSourceReference().getStartPosition(),
segment.getSourceReference().getLength());
+ }
+ }
+ }
+ }
}
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFMessageELCompletionEngine.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFMessageELCompletionEngine.java 2012-01-06
20:19:35 UTC (rev 37698)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFMessageELCompletionEngine.java 2012-01-06
20:43:13 UTC (rev 37699)
@@ -560,7 +560,7 @@
if(property == null) continue;
segment.addObject(property);
- PositionHolder h = PositionHolder.getPosition(p, null);
+ PositionHolder h = PositionHolder.getPosition(property, null);
h.update();
segment.setMessagePropertySourceReference(h.getStart(), name.length());
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/ELRefactorContributionFactory.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/ELRefactorContributionFactory.java 2012-01-06
20:19:35 UTC (rev 37698)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/ELRefactorContributionFactory.java 2012-01-06
20:43:13 UTC (rev 37699)
@@ -32,7 +32,7 @@
import org.eclipse.ui.services.IServiceLocator;
import org.jboss.tools.common.el.core.ELReference;
import org.jboss.tools.common.el.core.model.ELExpression;
-import org.jboss.tools.common.el.core.resolver.ELCompletionEngine;
+import org.jboss.tools.common.el.core.model.ELObject;
import org.jboss.tools.common.el.core.resolver.ELContext;
import org.jboss.tools.common.el.core.resolver.ELResolution;
import org.jboss.tools.common.el.core.resolver.ELResolver;
@@ -163,30 +163,47 @@
ELResolver[] resolvers = context.getElResolvers();
for(ELExpression operand : reference.getEl()){
- for (ELResolver resolver : resolvers) {
- ELResolution resolution = resolver.resolve(context, operand, selection.getOffset());
-
- if(resolution == null)
- continue;
-
- List<ELSegment> segments = resolution.getSegments();
-
- for(ELSegment segment : segments){
- if(!segment.isResolved())
- break;
-
- if(selection.getOffset() <=
reference.getStartPosition()+segment.getSourceReference().getStartPosition() &&
- selection.getOffset()+selection.getLength() >=
reference.getStartPosition()+segment.getSourceReference().getStartPosition()+segment.getSourceReference().getLength()
&&
- (segment instanceof MessagePropertyELSegment || segment instanceof
JavaMemberELSegment)){
- return segment;
+ ELSegment segment = getSegment(resolvers, context, selection, reference, operand);
+ if(segment != null){
+ return segment;
+ }
+ for(ELObject child : operand.getChildren()){
+ if(child instanceof ELExpression){
+ segment = getSegment(resolvers, context, selection, reference,
(ELExpression)child);
+ if(segment != null){
+ return segment;
}
}
-
}
}
return null;
}
+ private ELSegment getSegment(ELResolver[] resolvers, ELContext context, TextSelection
selection, ELReference reference, ELExpression operand){
+ for (ELResolver resolver : resolvers) {
+ ELResolution resolution = resolver.resolve(context, operand, selection.getOffset());
+
+ if(resolution == null)
+ continue;
+
+ List<ELSegment> segments = resolution.getSegments();
+
+ for(ELSegment segment : segments){
+ if(!segment.isResolved())
+ break;
+
+ if(segment.getSourceReference().getStartPosition() >= 0 &&
segment.getSourceReference().getLength() >= 0 &&
+ selection.getOffset() <=
reference.getStartPosition()+segment.getSourceReference().getStartPosition() &&
+ selection.getOffset()+selection.getLength() >=
reference.getStartPosition()+segment.getSourceReference().getStartPosition()+segment.getSourceReference().getLength()
&&
+ (segment instanceof MessagePropertyELSegment || segment instanceof
JavaMemberELSegment)){
+ return segment;
+ }
+ }
+
+ }
+ return null;
+ }
+
private static void saveAndBuild(){
if(!JsfUiPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().saveAllEditors(true))
return;
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.test/projects/JSFKickStartOldFormat/WebContent/pages/hello.jsp
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.test/projects/JSFKickStartOldFormat/WebContent/pages/hello.jsp 2012-01-06
20:19:35 UTC (rev 37698)
+++
trunk/jsf/tests/org.jboss.tools.jsf.test/projects/JSFKickStartOldFormat/WebContent/pages/hello.jsp 2012-01-06
20:43:13 UTC (rev 37699)
@@ -11,6 +11,7 @@
<body>
<f:view>
<h3>
+ <h:outputText value="#{user.name + Message.hello_message}" />,
<h:outputText value="#{Message.hello_message}" />,
<h:outputText value="#{user.name}" />!
</h3>
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/refactoring/ELVariableRefactoringTest.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/refactoring/ELVariableRefactoringTest.java 2012-01-06
20:19:35 UTC (rev 37698)
+++
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/refactoring/ELVariableRefactoringTest.java 2012-01-06
20:43:13 UTC (rev 37699)
@@ -8,12 +8,16 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.jboss.tools.common.base.test.AbstractRefactorTest;
+import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.jsf.el.refactoring.RenameELVariableProcessor;
import org.jboss.tools.test.util.ProjectImportTestSetup;
public class ELVariableRefactoringTest extends AbstractRefactorTest {
static String projectName = "JSFKickStartOldFormat";
static IProject project;
+
+ private static final String NEW_NAME = "cust";
+ private static final int NAME_LEN = 4;
public ELVariableRefactoringTest(){
super("EL Variable Refactoring Test");
@@ -25,37 +29,47 @@
}
public void testELVariableRename() throws CoreException {
+
ArrayList<TestChangeStructure> list = new
ArrayList<TestChangeStructure>();
-
+
+ IFile sourceFile =
project.getProject().getFile("/WebContent/pages/hello.jsp");
+
+ String sourceFileContent = FileUtil.getContentFromEditorOrFile(sourceFile);
+
+ int position = sourceFileContent.indexOf("user.name");
+
TestChangeStructure structure = new TestChangeStructure(project.getProject(),
"/WebContent/pages/hello.jsp");
- TestTextChange change = new TestTextChange(349, 8, "customer");
+ TestTextChange change = new TestTextChange(position, NAME_LEN, NEW_NAME);
structure.addTextChange(change);
+
+ position = sourceFileContent.indexOf("user.name", position+1);
+
+ change = new TestTextChange(position, NAME_LEN, NEW_NAME);
+ structure.addTextChange(change);
list.add(structure);
structure = new TestChangeStructure(project,
"/WebContent/WEB-INF/faces-config.xml");
- change = new TestTextChange(1815, 8, "customer");
+ change = new TestTextChange(1815, NAME_LEN, NEW_NAME);
structure.addTextChange(change);
list.add(structure);
structure = new TestChangeStructure(project,
"/WebContent/pages/inputUserName.jsp");
- change = new TestTextChange(494, 8, "customer");
+ change = new TestTextChange(494, NAME_LEN, NEW_NAME);
structure.addTextChange(change);
list.add(structure);
structure = new TestChangeStructure(project, "/WebContent/pages/el.jsp");
- change = new TestTextChange(83, 8, "customer");
+ change = new TestTextChange(83, NAME_LEN, NEW_NAME);
structure.addTextChange(change);
list.add(structure);
structure = new TestChangeStructure(project,
"/WebContent/testElRevalidation.xhtml");
- change = new TestTextChange(601, 8, "customer");
+ change = new TestTextChange(601, NAME_LEN, NEW_NAME);
structure.addTextChange(change);
list.add(structure);
- IFile sourceFile =
project.getProject().getFile("/WebContent/pages/hello.jsp");
-
RenameELVariableProcessor processor = new RenameELVariableProcessor(sourceFile,
"user");
- processor.setNewName("customer");
+ processor.setNewName(NEW_NAME);
checkRename(processor, list);
}
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/refactoring/MessagePropertyRefactoringTest.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/refactoring/MessagePropertyRefactoringTest.java 2012-01-06
20:19:35 UTC (rev 37698)
+++
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/refactoring/MessagePropertyRefactoringTest.java 2012-01-06
20:43:13 UTC (rev 37699)
@@ -18,6 +18,9 @@
static String projectName = "JSFKickStartOldFormat";
static IProject project;
+ private static final String NEW_NAME = "good______bye";
+ private static final int NAME_LEN = 13;
+
public MessagePropertyRefactoringTest(){
super("Resource Bundle Message Refactoring Test");
}
@@ -35,16 +38,23 @@
String sourceFileContent = FileUtil.getContentFromEditorOrFile(sourceFile);
int position = sourceFileContent.indexOf("Message.hello_message");
+ position += 8;
TestChangeStructure structure = new TestChangeStructure(project.getProject(),
"/WebContent/pages/hello.jsp");
- TestTextChange change = new TestTextChange(position+8, 8, "good_bye");
+ TestTextChange change = new TestTextChange(position, NAME_LEN, NEW_NAME);
structure.addTextChange(change);
+
+ position = sourceFileContent.indexOf("Message.hello_message", position);
+ position += 8;
+
+ change = new TestTextChange(position, NAME_LEN, NEW_NAME);
+ structure.addTextChange(change);
list.add(structure);
IFile propertyFile =
project.getProject().getFile("/JavaSource/demo/Messages.properties");
structure = new TestChangeStructure(project.getProject(),
"/JavaSource/demo/Messages.properties");
- change = new TestTextChange(0, 8, "good_bye");
+ change = new TestTextChange(0, NAME_LEN, NEW_NAME);
structure.addTextChange(change);
list.add(structure);
@@ -53,7 +63,7 @@
segment.setBaseName("demo.Messages");
segment.setMessagePropertySourceReference(0,10);
RenameMessagePropertyProcessor processor = new
RenameMessagePropertyProcessor(sourceFile, segment);
- processor.setNewName("good_bye");
+ processor.setNewName(NEW_NAME);
checkRename(processor, list);
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/refactoring/RefactorSearcher.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/refactoring/RefactorSearcher.java 2012-01-06
20:19:35 UTC (rev 37698)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/refactoring/RefactorSearcher.java 2012-01-06
20:43:13 UTC (rev 37699)
@@ -32,6 +32,7 @@
import org.jboss.tools.common.el.core.model.ELExpression;
import org.jboss.tools.common.el.core.model.ELInvocationExpression;
import org.jboss.tools.common.el.core.model.ELMethodInvocation;
+import org.jboss.tools.common.el.core.model.ELObject;
import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
import org.jboss.tools.common.el.core.resolver.ELCompletionEngine;
import org.jboss.tools.common.el.core.resolver.ELContext;
@@ -267,6 +268,29 @@
return true;
}
+ private void resolveByResolvers(ELExpression operand, ELResolver[] resolvers, ELContext
context, IRelevanceCheck[] checks, int offset, List<MatchArea> areas, IFile file){
+ for (int i = 0; i < resolvers.length; i++) {
+ ELResolver resolver = resolvers[i];
+ if (!(resolver instanceof ELCompletionEngine) ||
!checks[i].isRelevant(operand.getText()))
+ continue;
+
+ ELResolution resolution = resolver.resolve(context, operand, offset);
+
+ if(resolution != null) {
+ List<ELSegment> segments = resolution.findSegmentsByJavaElement(javaElement);
+ for(ELSegment segment : segments){
+ int o = offset+segment.getSourceReference().getStartPosition();
+ int l = segment.getSourceReference().getLength();
+
+ if(!contains(areas, o, l)){
+ match(file, o, l);
+ areas.add(new MatchArea(o, l));
+ }
+ }
+ }
+ }
+ }
+
protected void searchInCach(IFile file){
ELResolver[] resolvers = ELResolverFactoryManager.getInstance().getResolvers(file);
@@ -284,24 +308,11 @@
for(ELReference reference : references){
int offset = reference.getStartPosition();
for(ELExpression operand : reference.getEl()){
- for (int i = 0; i < resolvers.length; i++) {
- ELResolver resolver = resolvers[i];
- if (!(resolver instanceof ELCompletionEngine) ||
!checks[i].isRelevant(operand.getText()))
- continue;
-
- ELResolution resolution = resolver.resolve(context, operand, offset);
-
- if(resolution != null) {
- List<ELSegment> segments =
resolution.findSegmentsByJavaElement(javaElement);
- for(ELSegment segment : segments){
- int o = offset+segment.getSourceReference().getStartPosition();
- int l = segment.getSourceReference().getLength();
-
- if(!contains(areas, o, l)){
- match(file, o, l);
- areas.add(new MatchArea(o, l));
- }
- }
+ resolveByResolvers(operand, resolvers, context, checks, offset, areas, file);
+
+ for(ELObject child : operand.getChildren()){
+ if(child instanceof ELExpression){
+ resolveByResolvers((ELExpression)child, resolvers, context, checks, offset, areas,
file);
}
}
}
@@ -317,6 +328,14 @@
checkMatch(file, expression, offset+getOffset(expression),
getLength(expression));
}
}
+ for(ELObject child : operand.getChildren()){
+ if(child instanceof ELInvocationExpression){
+ ELInvocationExpression expression =
findComponentReference((ELInvocationExpression)child);
+ if(expression != null){
+ checkMatch(file, expression, offset+getOffset(expression),
getLength(expression));
+ }
+ }
+ }
}
}
}