[jbosstools-commits] JBoss Tools SVN: r21020 - in trunk/jsf/plugins: org.jboss.tools.jsf.ui and 1 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Mar 25 11:10:44 EDT 2010


Author: dazarov
Date: 2010-03-25 11:10:43 -0400 (Thu, 25 Mar 2010)
New Revision: 21020

Modified:
   trunk/jsf/plugins/org.jboss.tools.jsf.ui/plugin.xml
   trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/RenameELVariableWizard.java
   trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/ELRenameProcessor.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/ELRenameProcessor.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/ELRenameProcessor.java	2010-03-25 14:58:19 UTC (rev 21019)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/ELRenameProcessor.java	2010-03-25 15:10:43 UTC (rev 21020)
@@ -16,7 +16,6 @@
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.ltk.core.refactoring.CompositeChange;
 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
@@ -27,11 +26,11 @@
 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.ELCorePlugin;
 import org.jboss.tools.common.el.core.ElCoreMessages;
+import org.jboss.tools.common.el.core.model.ELInvocationExpression;
+import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
 import org.jboss.tools.common.model.project.ProjectHome;
 import org.jboss.tools.common.text.ITextSourceReference;
-import org.jboss.tools.common.util.FileUtil;
 
 /**
  * @author Daniel Azarov
@@ -117,90 +116,9 @@
 		return flag;
 	}
 	
-	private void changeXMLNode(ITextSourceReference location, IFile file){
-		if(isBadLocation(location, file))
-			return;
-		
-		if(!isFileCorrect(file))
-			return;
-
-		String content = null;
-		try {
-			content = FileUtil.readStream(file);
-		} catch (CoreException e) {
-			ELCorePlugin.getDefault().logError(e);
-		}
-
-		String text = content.substring(location.getStartPosition(), location.getStartPosition()+location.getLength());
-		if(text.startsWith("<")){ //$NON-NLS-1$
-			int position = text.lastIndexOf("/>"); //$NON-NLS-1$
-			if(position < 0){
-				position = text.lastIndexOf(">"); //$NON-NLS-1$
-			}
-			change(file, location.getStartPosition()+position, 0, " name=\""+getNewName()+"\""); //$NON-NLS-1$ //$NON-NLS-2$
-		}else{
-			change(file, location.getStartPosition(), location.getLength(), getNewName());
-		}
-	}
 	
-	private void changeAnnotation(ITextSourceReference location, IFile file){
-		if(isBadLocation(location, file))
-			return;
-		
-		if(!isFileCorrect(file))
-			return;
-
-		String content = null;
-		try {
-			content = FileUtil.readStream(file);
-		} catch (CoreException e) {
-			ELCorePlugin.getDefault().logError(e);
-		}
-
-		String text = content.substring(location.getStartPosition(), location.getStartPosition()+location.getLength());
-		int openBracket = text.indexOf("("); //$NON-NLS-1$
-		int openQuote = text.indexOf("\""); //$NON-NLS-1$
-		if(openBracket >= 0){
-			int closeBracket = text.indexOf(")", openBracket); //$NON-NLS-1$
-			
-			int equals = text.indexOf("=", openBracket); //$NON-NLS-1$
-			int value = text.indexOf("value", openBracket); //$NON-NLS-1$
-			
-			if(closeBracket == openBracket+1){ // empty brackets
-				String newText = "\""+getNewName()+"\""; //$NON-NLS-1$ //$NON-NLS-2$
-				change(file, location.getStartPosition()+openBracket+1, 0, newText);
-			}else if(value > 0){ // construction value="name" found so change name
-				String newText = text.replace(getOldName(), getNewName());
-				change(file, location.getStartPosition(), location.getLength(), newText);
-			}else if(equals > 0){ // other parameters are found
-				String newText = "value=\""+getNewName()+"\","; //$NON-NLS-1$ //$NON-NLS-2$
-				change(file, location.getStartPosition()+openBracket+1, 0, newText);
-			}else{ // other cases
-				String newText = text.replace(getOldName(), getNewName());
-				change(file, location.getStartPosition(), location.getLength(), newText);
-			}
-		}else if(openQuote >= 0){
-			int closeQuota = text.indexOf("\"", openQuote); //$NON-NLS-1$
-			
-			if(closeQuota == openQuote+1){ // empty quotas
-				String newText = "\""+getNewName()+"\""; //$NON-NLS-1$ //$NON-NLS-2$
-				change(file, location.getStartPosition()+openQuote+1, 0, newText);
-			}else{ // the other cases
-				String newText = text.replace(getOldName(), getNewName());
-				change(file, location.getStartPosition(), location.getLength(), newText);
-			}
-		}else{
-			String newText = "(\""+getNewName()+"\")"; //$NON-NLS-1$ //$NON-NLS-2$
-			change(file, location.getStartPosition()+location.getLength(), 0, newText);
-		}
-	}
 	
-	private void clearChanges(){
-		keys.clear();
-	}
-	
 	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);
@@ -232,18 +150,6 @@
 		}
 		
 		
-		private boolean checkFolder(IResource resource, IResource[] sources, IPath output){
-			for(IResource folder : sources){
-				if(resource.equals(folder))
-					return false;
-			}
-			
-			if(resource.getFullPath().equals(output))
-				return false;
-			
-			return true;
-		}
-		
 		ArrayList<String> keys = new ArrayList<String>();
 		
 		@Override
@@ -266,11 +172,27 @@
 			change(file, offset, length, newName);
 		}
 
-
 		@Override
 		protected boolean isFileCorrect(IFile file) {
 			return ELRenameProcessor.this.isFileCorrect(file);
 		}
+		
+		protected ELInvocationExpression findComponentReference(ELInvocationExpression invocationExpression){
+			ELInvocationExpression invExp = invocationExpression;
+			while(invExp != null){
+				if(invExp instanceof ELPropertyInvocation){
+					if(((ELPropertyInvocation)invExp).getQualifiedName() != null && ((ELPropertyInvocation)invExp).getQualifiedName().equals(propertyName))
+						return invExp;
+					else
+						invExp = invExp.getLeft();
+					
+				}else{
+					invExp = invExp.getLeft();
+				}
+			}
+			return null;
+		}
+
 	
 	}
 }
\ No newline at end of file

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-25 14:58:19 UTC (rev 21019)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/el/refactoring/RenameELVariableProcessor.java	2010-03-25 15:10:43 UTC (rev 21020)
@@ -11,7 +11,6 @@
 package org.jboss.tools.jsf.el.refactoring;
 
 import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.OperationCanceledException;
@@ -23,6 +22,12 @@
 import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
 import org.eclipse.ltk.internal.core.refactoring.Messages;
 import org.jboss.tools.common.el.core.ElCoreMessages;
+import org.jboss.tools.common.model.XModel;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.project.IModelNature;
+import org.jboss.tools.common.model.refactoring.RenameModelObjectChange;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.jsf.model.pv.JSFBeanSearcher;
 
 /**
  * @author Daniel Azarov
@@ -64,11 +69,8 @@
 	public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
 			throws CoreException, OperationCanceledException {
 		RefactoringStatus result = new RefactoringStatus();
-		boolean status = false;
 		
-		status = checkELContextVariable();
-		
-		if(!status)
+		if(findManagedBean() == null)
 			result.addFatalError(Messages.format(ElCoreMessages.RENAME_EL_VARIABLE_PROCESSOR_CAN_NOT_FIND_EL_VARIABLE, getOldName()));
 		return result;
 	}
@@ -84,17 +86,6 @@
 		return rootChange;
 	}
 	
-	
-	private boolean checkELContextVariable(){
-		boolean status = true;
-		
-		IProject[] projects = getSearcher().getProjects();
-		for (IProject project : projects) {
-			// TODO:
-		}
-		return status;
-	}
-	
 	/*
 	 * (non-Javadoc)
 	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getElements()
@@ -142,6 +133,25 @@
 	}
 	
 	private void renameELVariable(IProgressMonitor pm, IFile file){
-		getSearcher().findELReferences();
+		XModelObject managedBean = findManagedBean();
+		if(managedBean != null){
+			Change managedBeanChange = RenameModelObjectChange.createChange(new XModelObject[]{managedBean}, getNewName(), "managed-bean-name");
+			rootChange.add(managedBeanChange);
+			getSearcher().findELReferences();
+		}
 	}
+	
+	private XModelObject findManagedBean(){
+		IModelNature nature = EclipseResourceUtil.getModelNature(file.getProject());
+		if(nature == null)
+			return null;
+		XModel model = nature.getModel();
+		if(model == null)
+			return null;
+		JSFBeanSearcher beanSearcher = new JSFBeanSearcher(model);
+		beanSearcher.parse(getOldName());
+		XModelObject managedBean = beanSearcher.getBean();
+		
+		return managedBean;
+	}
 }
\ No newline at end of file

Modified: trunk/jsf/plugins/org.jboss.tools.jsf.ui/plugin.xml
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.ui/plugin.xml	2010-03-25 14:58:19 UTC (rev 21019)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.ui/plugin.xml	2010-03-25 15:10:43 UTC (rev 21020)
@@ -444,12 +444,12 @@
     </extension>
     
     <!-- Refactorng -->
-	<!--extension
+	<extension
 		point="org.eclipse.ui.menus">
     <menuContribution
           class="org.jboss.tools.jsf.ui.el.refactoring.ELRefactorContributionFactory"
           locationURI="popup:org.eclipse.ui.popup.any?after=save">
     </menuContribution>
-	</extension--> 
+	</extension> 
 
 </plugin>

Modified: trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/RenameELVariableWizard.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/RenameELVariableWizard.java	2010-03-25 14:58:19 UTC (rev 21019)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/RenameELVariableWizard.java	2010-03-25 15:10:43 UTC (rev 21020)
@@ -102,7 +102,7 @@
 		}
 		
 		private void initializeRefactoring() {
-			//processor.setNewName(editor.getValueAsString());
+			processor.setNewName(editor.getValueAsString());
 		}
 		
 	}



More information about the jbosstools-commits mailing list