Author: dazarov
Date: 2010-03-29 09:46:13 -0400 (Mon, 29 Mar 2010)
New Revision: 21116
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/RenameELVariableProcessor.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4990
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RenameELVariableProcessor.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RenameELVariableProcessor.java 2010-03-29
13:09:02 UTC (rev 21115)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RenameELVariableProcessor.java 2010-03-29
13:46:13 UTC (rev 21116)
@@ -33,6 +33,7 @@
* @author Daniel Azarov
*/
public class RenameELVariableProcessor extends ELRenameProcessor {
+ private final static String MANAGED_BEAN_NAME_ATTRIBUTE = "managed-bean-name";
IFile file;
/**
@@ -70,7 +71,7 @@
throws CoreException, OperationCanceledException {
RefactoringStatus result = new RefactoringStatus();
- if(findManagedBean() == null)
+ if(findManagedBean(file, getOldName()) == null)
result.addFatalError(Messages.format(ElCoreMessages.RENAME_EL_VARIABLE_PROCESSOR_CAN_NOT_FIND_EL_VARIABLE,
getOldName()));
return result;
}
@@ -133,15 +134,15 @@
}
private void renameELVariable(IProgressMonitor pm, IFile file){
- XModelObject managedBean = findManagedBean();
+ XModelObject managedBean = findManagedBean(file, getOldName());
if(managedBean != null){
- Change managedBeanChange = RenameModelObjectChange.createChange(new
XModelObject[]{managedBean}, getNewName(), "managed-bean-name");
+ Change managedBeanChange = RenameModelObjectChange.createChange(new
XModelObject[]{managedBean}, getNewName(), MANAGED_BEAN_NAME_ATTRIBUTE);
rootChange.add(managedBeanChange);
getSearcher().findELReferences();
}
}
- private XModelObject findManagedBean(){
+ public static XModelObject findManagedBean(IFile file, String name){
IModelNature nature = EclipseResourceUtil.getModelNature(file.getProject());
if(nature == null)
return null;
@@ -149,9 +150,17 @@
if(model == null)
return null;
JSFBeanSearcher beanSearcher = new JSFBeanSearcher(model);
- beanSearcher.parse(getOldName());
+ beanSearcher.parse(name);
XModelObject managedBean = beanSearcher.getBean();
return managedBean;
}
+
+ public static String getManagedBeanName(IFile file, String text){
+ XModelObject managedBean = findManagedBean(file, text);
+ if(managedBean != null){
+ return managedBean.getAttributeValue(MANAGED_BEAN_NAME_ATTRIBUTE);
+ }
+ return null;
+ }
}
\ No newline at end of file
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 2010-03-29
13:09:02 UTC (rev 21115)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/ELRefactorContributionFactory.java 2010-03-29
13:46:13 UTC (rev 21116)
@@ -13,17 +13,10 @@
import java.io.IOException;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.internal.ui.text.FastJavaPartitionScanner;
import org.eclipse.jdt.ui.text.IJavaPartitions;
import org.eclipse.jface.action.Action;
@@ -61,13 +54,12 @@
import org.jboss.tools.common.el.core.parser.ELParser;
import org.jboss.tools.common.el.core.parser.ELParserUtil;
import org.jboss.tools.common.model.ui.editor.EditorPartWrapper;
-import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.propertieseditor.PropertiesCompoundEditor;
import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.jsf.el.refactoring.RenameELVariableProcessor;
import org.jboss.tools.jsf.el.refactoring.RenameELVariableRefactoring;
-import org.jboss.tools.jsf.ui.JsfUiPlugin;
import org.jboss.tools.jsf.ui.JsfUIMessages;
+import org.jboss.tools.jsf.ui.JsfUiPlugin;
import org.jboss.tools.jst.web.ui.editors.WebCompoundEditor;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -212,8 +204,13 @@
for(ELInvocationExpression ie : instance.getExpression().getInvocations()){
ELPropertyInvocation pi = findELVariable(ie);
if(pi != null){
- if(offset+pi.getStartPosition() == selection.getOffset() && pi.getLength()
== selection.getLength())
- return true;
+ if(offset+pi.getStartPosition() == selection.getOffset() && pi.getLength()
== selection.getLength()){
+ String beanName = RenameELVariableProcessor.getManagedBeanName(file,
pi.getText());
+ if(beanName != null){
+ selectedText = beanName;
+ return true;
+ }
+ }
}
}
}