[jbosstools-commits] JBoss Tools SVN: r17588 - in trunk/seam/plugins: org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search and 1 other directory.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Tue Sep 15 11:02:31 EDT 2009
Author: dazarov
Date: 2009-09-15 11:02:30 -0400 (Tue, 15 Sep 2009)
New Revision: 17588
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/SeamRenameMethodParticipant.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-4856
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-15 14:54:19 UTC (rev 17587)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRefactorSearcher.java 2009-09-15 15:02:30 UTC (rev 17588)
@@ -253,10 +253,10 @@
if(expression != null){
if(expression instanceof ELPropertyInvocation){
ELPropertyInvocation pi = (ELPropertyInvocation)expression;
- match(file, offset+pi.getStartPosition(), pi.getName().getStart()+pi.getName().getLength()-pi.getStartPosition());
+ match(file, offset+pi.getName().getStart(), pi.getName().getLength());
}else if(expression instanceof ELMethodInvocation){
ELMethodInvocation mi = (ELMethodInvocation)expression;
- match(file, offset+mi.getStartPosition(), mi.getName().getStart()+mi.getName().getLength()-mi.getStartPosition());
+ match(file, offset+mi.getName().getStart(), mi.getName().getLength());
}
}
}
@@ -325,12 +325,16 @@
protected abstract void match(IFile file, int offset, int length);
public static String getPropertyName(String methodName){
- if(methodName.startsWith(GET) || methodName.startsWith(SET))
- return methodName.substring(3).toLowerCase();
+ if(methodName.startsWith(GET) || methodName.startsWith(SET)){
+ String name = methodName.substring(3);
+ return name.substring(0, 1).toLowerCase()+name.substring(1);
+ }
- if(methodName.startsWith(IS))
- return methodName.substring(2).toLowerCase();
+ if(methodName.startsWith(IS)){
+ String name = methodName.substring(2);
+ return name.substring(0, 1).toLowerCase()+name.substring(1);
+ }
- return methodName.toLowerCase();
+ return methodName;
}
}
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameMethodParticipant.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameMethodParticipant.java 2009-09-15 14:54:19 UTC (rev 17587)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameMethodParticipant.java 2009-09-15 15:02:30 UTC (rev 17588)
@@ -10,33 +10,52 @@
******************************************************************************/
package org.jboss.tools.seam.internal.core.refactoring;
+import java.util.ArrayList;
+
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.TextFileChange;
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
+import org.eclipse.ltk.internal.core.refactoring.Messages;
+import org.eclipse.text.edits.MultiTextEdit;
+import org.eclipse.text.edits.ReplaceEdit;
+import org.eclipse.text.edits.TextEdit;
+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.ELPropertyInvocation;
+import org.jboss.tools.seam.core.SeamCoreMessages;
public class SeamRenameMethodParticipant extends RenameParticipant{
private IMethod method;
private String oldName;
private String newName;
private SeamRenameMethodSearcher searcher;
+ private RefactoringStatus status;
+ private CompositeChange rootChange;
+ private TextFileChange lastChange;
+ private ArrayList<String> keys = new ArrayList<String>();
@Override
public RefactoringStatus checkConditions(IProgressMonitor pm,
CheckConditionsContext context) throws OperationCanceledException {
- return null;
+ searcher.findELReferences();
+
+ return status;
}
@Override
public Change createChange(IProgressMonitor pm) throws CoreException,
OperationCanceledException {
- return null;
+ return rootChange;
}
@Override
@@ -47,16 +66,49 @@
@Override
protected boolean initialize(Object element) {
if(element instanceof IMethod){
+ status = new RefactoringStatus();
+
+ rootChange = new CompositeChange("");
method = (IMethod)element;
- oldName = method.getElementName();
- newName = getArguments().getNewName();
+ oldName = SeamRenameMethodSearcher.getPropertyName(method.getElementName());
+ newName = SeamRenameMethodSearcher.getPropertyName(getArguments().getNewName());
searcher = new SeamRenameMethodSearcher((IFile)method.getResource(), oldName);
return true;
}
return false;
}
+ protected TextFileChange getChange(IFile file){
+ if(lastChange != null && lastChange.getFile().equals(file))
+ return lastChange;
+
+ for(int i=0; i < rootChange.getChildren().length; i++){
+ TextFileChange change = (TextFileChange)rootChange.getChildren()[i];
+ if(change.getFile().equals(file)){
+ lastChange = change;
+ return lastChange;
+ }
+ }
+ lastChange = new TextFileChange(file.getName(), file);
+ MultiTextEdit root = new MultiTextEdit();
+ lastChange.setEdit(root);
+ rootChange.add(lastChange);
+
+ return lastChange;
+ }
+
+ private void change(IFile file, int offset, int length, String text){
+ //System.out.println("change file - "+file.getFullPath()+" offset - "+offset+" len - "+length+" text <"+text+">");
+ String key = file.getFullPath().toString()+" "+offset;
+ if(!keys.contains(key)){
+ TextFileChange change = getChange(file);
+ TextEdit edit = new ReplaceEdit(offset, length, text);
+ //change.addEdit(edit);
+ keys.add(key);
+ }
+ }
+
class SeamRenameMethodSearcher extends SeamRefactorSearcher{
public SeamRenameMethodSearcher(IFile file, String name){
super(file, name);
@@ -64,11 +116,37 @@
@Override
protected boolean isFileCorrect(IFile file) {
- return false;
+ if(!file.isSynchronized(IResource.DEPTH_ZERO)){
+ status.addFatalError(Messages.format(SeamCoreMessages.SEAM_RENAME_PROCESSOR_OUT_OF_SYNC_FILE, file.getFullPath().toString()));
+ return false;
+ }else if(file.isPhantom()){
+ status.addFatalError(Messages.format(SeamCoreMessages.SEAM_RENAME_PROCESSOR_ERROR_PHANTOM_FILE, file.getFullPath().toString()));
+ return false;
+ }else if(file.isReadOnly()){
+ status.addFatalError(Messages.format(SeamCoreMessages.SEAM_RENAME_PROCESSOR_ERROR_READ_ONLY_FILE, file.getFullPath().toString()));
+ return false;
+ }
+ return true;
}
+
+ protected ELInvocationExpression findComponentReference(ELInvocationExpression invocationExpression){
+ ELInvocationExpression invExp = invocationExpression;
+ while(invExp != null){
+ if(invExp instanceof ELMethodInvocation || invExp instanceof ELPropertyInvocation){
+ if(invExp.getMemberName() != null && invExp.getMemberName().equals(propertyName))
+ return invExp;
+ else
+ invExp = invExp.getLeft();
+ }else{
+ invExp = invExp.getLeft();
+ }
+ }
+ return null;
+ }
@Override
protected void match(IFile file, int offset, int length) {
+ change(file, offset, length, newName);
}
}
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-15 14:54:19 UTC (rev 17587)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamELReferencesQueryParticipant.java 2009-09-15 15:02:30 UTC (rev 17588)
@@ -93,7 +93,7 @@
ELInvocationExpression invExp = invocationExpression;
while(invExp != null){
if(invExp instanceof ELMethodInvocation || invExp instanceof ELPropertyInvocation){
- if(invExp.getMemberName() != null && invExp.getMemberName().equalsIgnoreCase(propertyName))
+ if(invExp.getMemberName() != null && invExp.getMemberName().equals(propertyName))
return invExp;
else
invExp = invExp.getLeft();
More information about the jbosstools-commits
mailing list