Author: dazarov
Date: 2009-05-28 08:53:45 -0400 (Thu, 28 May 2009)
New Revision: 15582
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/refactoring/SeamContextVariableRenameHandler.java
Log:
Seam Context Variable Refactoring
https://jira.jboss.org/jira/browse/JBIDE-1077
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/refactoring/SeamContextVariableRenameHandler.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/refactoring/SeamContextVariableRenameHandler.java 2009-05-28
12:07:34 UTC (rev 15581)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/refactoring/SeamContextVariableRenameHandler.java 2009-05-28
12:53:45 UTC (rev 15582)
@@ -34,6 +34,12 @@
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+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.ELModel;
+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.util.FileUtil;
import org.jboss.tools.seam.core.ISeamComponent;
import org.jboss.tools.seam.core.SeamCorePlugin;
@@ -51,6 +57,8 @@
private static final String XHTML_EXT = "xhtml"; //$NON-NLS-1$
private static final String JSP_EXT = "jsp"; //$NON-NLS-1$
private static final String PROPERTIES_EXT = "properties"; //$NON-NLS-1$
+
+ String selectedText = "";
/*
* (non-Javadoc)
*
@@ -72,9 +80,9 @@
if(sel instanceof TextSelection && editor.getEditorInput() instanceof
FileEditorInput){
TextSelection selection = (TextSelection)sel;
- String text = selection.getText();
+ selectedText = selection.getText();
- System.out.println("Selection text - "+text);
+ System.out.println("Selection text - "+selectedText);
FileEditorInput input = (FileEditorInput)editor.getEditorInput();
@@ -88,11 +96,11 @@
SeamCorePlugin.getPluginLog().logError(e);
return null;
}
- if(ext.equalsIgnoreCase(JAVA_EXT)){
+ if(JAVA_EXT.equalsIgnoreCase(ext)){
findContextVariableInJava(file, content, selection);
- } else if(ext.equalsIgnoreCase(XML_EXT) || ext.equalsIgnoreCase(XHTML_EXT) ||
ext.equalsIgnoreCase(JSP_EXT))
+ } else if(XML_EXT.equalsIgnoreCase(ext) || XHTML_EXT.equalsIgnoreCase(ext) ||
JSP_EXT.equalsIgnoreCase(ext))
findContextVariableInDOM(file, content, selection);
- else if(ext.equalsIgnoreCase(PROPERTIES_EXT))
+ else if(PROPERTIES_EXT.equalsIgnoreCase(ext))
findContextVariableInProperties(file, content, selection);
}
return null;
@@ -110,7 +118,7 @@
int offset = scaner.getTokenOffset();
String value = document.get(offset, length);
if(value.indexOf('{')>-1) {
- //scanString(file, value, offset);
+ scanString(file, value, offset);
}
}
token = scaner.nextToken();
@@ -120,6 +128,38 @@
}
}
+ private void scanString(IFile file, String string, int offset) {
+ int startEl = string.indexOf("#{"); //$NON-NLS-1$
+ if(startEl>-1) {
+ ELParser parser = ELParserUtil.getJbossFactory().createParser();
+ ELModel model = parser.parse(string);
+ for (ELInstance instance : model.getInstances()) {
+ for(ELInvocationExpression ie : instance.getExpression().getInvocations()){
+ ELPropertyInvocation pi = findComponentReference(ie);
+ if(pi != null){
+
+ }
+ }
+ }
+ }
+ }
+
+ private ELPropertyInvocation findComponentReference(ELInvocationExpression
invocationExpression){
+ ELInvocationExpression invExp = invocationExpression;
+ while(invExp != null){
+ if(invExp instanceof ELPropertyInvocation){
+ if(((ELPropertyInvocation)invExp).getQualifiedName() != null &&
((ELPropertyInvocation)invExp).getQualifiedName().equals(selectedText))
+ return (ELPropertyInvocation)invExp;
+ else
+ invExp = invExp.getLeft();
+
+ }else{
+ invExp = invExp.getLeft();
+ }
+ }
+ return null;
+ }
+
private void findContextVariableInDOM(IFile file, String content, TextSelection
selection){
IModelManager manager = StructuredModelManager.getModelManager();
if(manager == null) {