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

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Wed Jul 21 08:08:01 EDT 2010


Author: dazarov
Date: 2010-07-21 08:08:00 -0400 (Wed, 21 Jul 2010)
New Revision: 23635

Modified:
   trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/JsfUIMessages.java
   trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/MessagesFileRenameParticipant.java
   trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/messages.properties
   trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/refactoring/SearchUtil.java
Log:
https://jira.jboss.org/browse/JBIDE-4858

Modified: trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/JsfUIMessages.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/JsfUIMessages.java	2010-07-21 11:41:37 UTC (rev 23634)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/JsfUIMessages.java	2010-07-21 12:08:00 UTC (rev 23635)
@@ -44,6 +44,7 @@
 	public static String SKIP_BUTTON_LABEL;
 	
 	public static String MESSAGES_FILE_RENAME_PARTICIPANT_UPDATE_MESSAGE_BUNDLE_REFERENCES;
+	public static String MESSAGES_FILE_RENAME_PARTICIPANT_FILE_NAME_SHOULD_BE_WITH_THE_SAME_EXTENSION;
 	
 	static {
 		// initialize resource bundle

Modified: trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/MessagesFileRenameParticipant.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/MessagesFileRenameParticipant.java	2010-07-21 11:41:37 UTC (rev 23634)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/el/refactoring/MessagesFileRenameParticipant.java	2010-07-21 12:08:00 UTC (rev 23635)
@@ -34,9 +34,10 @@
 
 public class MessagesFileRenameParticipant extends RenameParticipant {
 	private static final String PROPERTIES_EXT = "properties";
-	private RefactoringStatus status;
+	//private RefactoringStatus status;
 	private CompositeChange rootChange;
 	private IFile file;
+	private String newName=null;
 
 	@Override
 	protected boolean initialize(Object element) {
@@ -45,31 +46,7 @@
 			file = (IFile)element;
 			String ext = file.getFileExtension();
 			if(PROPERTIES_EXT.equals(ext)){
-				
-				IPath path = file.getFullPath();
-				
-				String newName = getArguments().getNewName();
-				newName = newName.replace(".properties","");
-				String oldName = getQualifiedName(path);
-				String fileName = file.getName().replace(".properties","");
-				newName = "\""+oldName.replace(fileName,newName)+"\"";
-				
-				SearchUtil su = new SearchUtil(SearchUtil.XML_FILES, oldName);
-				
-				SearchResult result = su.searchInNodeAttribute(file.getProject(), ":loadBundle", "basename");
-				if(result.getEntries().size() == 0)
-					return false;
-				
-				for(FileResult fr : result.getEntries()){
-					TextFileChange fileChange = new TextFileChange(fr.getFile().getName(), fr.getFile());
-					MultiTextEdit root = new MultiTextEdit();
-					fileChange.setEdit(root);
-					rootChange.add(fileChange);
-					for(int position : fr.getPositions()){
-						TextEdit edit = new ReplaceEdit(position, oldName.length(), newName);
-						fileChange.addEdit(edit);
-					}
-				}
+				newName = getArguments().getNewName();
 				return true;
 			}
 		}
@@ -88,7 +65,7 @@
 					String pathString = relativePath.toString();
 					pathString = pathString.replace(".properties","");
 					pathString = pathString.replace("/",".");
-					return "\""+pathString+"\"";
+					return pathString;
 				}
 			}
 		}
@@ -98,7 +75,38 @@
 	@Override
 	public RefactoringStatus checkConditions(IProgressMonitor pm,
 			CheckConditionsContext context) throws OperationCanceledException {
-		
+		RefactoringStatus status = new RefactoringStatus();
+		if(newName != null){
+			if(!newName.endsWith(".properties")){
+				status.addFatalError(JsfUIMessages.MESSAGES_FILE_RENAME_PARTICIPANT_FILE_NAME_SHOULD_BE_WITH_THE_SAME_EXTENSION);
+				return status;
+			}
+			
+			IPath path = file.getFullPath();
+			
+			newName = newName.replace(".properties","");
+			String oldName = getQualifiedName(path);
+			String fileName = file.getName().replace(".properties","");
+			newName = oldName.replace(fileName,newName);
+			
+			SearchUtil su = new SearchUtil(SearchUtil.XML_FILES, oldName);
+			
+			SearchResult result = su.searchInNodeAttribute(file.getProject(), ":loadBundle", "basename");
+			if(result.getEntries().size() == 0)
+				return status;
+			
+			for(FileResult fr : result.getEntries()){
+				TextFileChange fileChange = new TextFileChange(fr.getFile().getName(), fr.getFile());
+				MultiTextEdit root = new MultiTextEdit();
+				fileChange.setEdit(root);
+				rootChange.add(fileChange);
+				for(int position : fr.getPositions()){
+					TextEdit edit = new ReplaceEdit(position, oldName.length(), newName);
+					fileChange.addEdit(edit);
+				}
+			}
+
+		}
 		return status;
 	}
 

Modified: trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/messages.properties
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/messages.properties	2010-07-21 11:41:37 UTC (rev 23634)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.ui/src/org/jboss/tools/jsf/ui/messages.properties	2010-07-21 12:08:00 UTC (rev 23635)
@@ -33,4 +33,5 @@
 DONT_SHOW_CHECKER_DIALOG=Do not show this dialog again!
 MISSING_NATURES_INFO_MESSAGE_TITLE=Missing Natures
 SKIP_BUTTON_LABEL=Skip
-MESSAGES_FILE_RENAME_PARTICIPANT_UPDATE_MESSAGE_BUNDLE_REFERENCES=Update Message Bundle References
\ No newline at end of file
+MESSAGES_FILE_RENAME_PARTICIPANT_UPDATE_MESSAGE_BUNDLE_REFERENCES=Update Message Bundle References
+MESSAGES_FILE_RENAME_PARTICIPANT_FILE_NAME_SHOULD_BE_WITH_THE_SAME_EXTENSION=New file name should be with the same extension
\ No newline at end of file

Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/refactoring/SearchUtil.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/refactoring/SearchUtil.java	2010-07-21 11:41:37 UTC (rev 23634)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/refactoring/SearchUtil.java	2010-07-21 12:08:00 UTC (rev 23635)
@@ -22,7 +22,13 @@
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.internal.ui.text.FastJavaPartitionScanner;
+import org.eclipse.jdt.ui.text.IJavaPartitions;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
 import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.Token;
 import org.eclipse.wst.sse.core.StructuredModelManager;
 import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
 import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
@@ -100,10 +106,10 @@
 			// searching java, xml and property files in source folders
 			if(javaProject != null){
 				for(IResource resource : EclipseResourceUtil.getJavaSourceRoots(project)){
-					//if(resource instanceof IFolder)
-						//scanForJava((IFolder) resource);
-					//else if(resource instanceof IFile)
-						//scanForJava((IFile) resource);
+					if(resource instanceof IFolder)
+						scanForJava((IFolder) resource);
+					else if(resource instanceof IFile)
+						scanForJava((IFile) resource);
 				}
 			}
 		}
@@ -154,6 +160,19 @@
 		}
 	}
 	
+	private void scanForJava(IContainer container){
+		try{
+			for(IResource resource : container.members()){
+				if(resource instanceof IFolder)
+					scanForJava((IFolder) resource);
+				else if(resource instanceof IFile)
+					scanForJava((IFile) resource);
+			}
+		}catch(CoreException ex){
+			ELCorePlugin.getDefault().logError(ex);
+		}
+	}
+	
 	private void scan(IFile file){
 		if(isFileCorrect(file)) {
 			String fileContent=null;
@@ -169,6 +188,21 @@
 			}
 		}
 	}
+	
+	private void scanForJava(IFile file){
+		if(isFileCorrect(file)) {
+			String fileContent=null;
+			try {
+				fileContent = FileUtil.readStream(file);
+			} catch (CoreException e) {
+				ELCorePlugin.getDefault().logError(e);
+			}
+			String ext = file.getFileExtension();			
+			if(JAVA_EXT.equalsIgnoreCase(ext)) {
+				scanInJava(file, fileContent);
+			}
+		}
+	}
 
 	
 	private boolean scanInDOM(IFile file, String content){
@@ -222,6 +256,34 @@
 		return false;
 	}
 	
+	private boolean scanInJava(IFile file, String content){
+		try {
+			FastJavaPartitionScanner scaner = new FastJavaPartitionScanner();
+			Document document = new Document(content);
+			scaner.setRange(document, 0, document.getLength());
+			IToken token = scaner.nextToken();
+			while(token!=null && token!=Token.EOF) {
+				if(IJavaPartitions.JAVA_STRING.equals(token.getData())) {
+					int length = scaner.getTokenLength();
+					int offset = scaner.getTokenOffset();
+					String value = document.get(offset, length);
+					if(searchString.equals(value)){
+						if(lastResult == null || !lastResult.getFile().equals(file)){
+							lastResult = new FileResult(file);
+							result.getEntries().add(lastResult);
+						}
+						
+						lastResult.addPosition(length);
+					}
+				}
+				token = scaner.nextToken();
+			}
+		} catch (BadLocationException e) {
+			WebKbPlugin.getDefault().logError(e);
+		}
+		return false;
+	}
+	
 	private boolean scanNodeContent(IFile file, IStructuredDocumentRegion node, String regionType) {
 		boolean status = false;
 		
@@ -230,16 +292,22 @@
 		
 		ITextRegionList regions = node.getRegions();
 		for(int i=0; i<regions.size(); i++) {
+			String tempSearchString = searchString;
+			int delta = 0;
 			ITextRegion region = regions.get(i);
 			if(region.getType() == regionType) {
-				String text = node.getFullText(region).trim();
-				if(searchString.equals(text)){
+				String text = node.getFullText(region);
+				if(text.startsWith("\"")){
+					tempSearchString = "\""+tempSearchString;
+					delta = 1;
+				}
+				if(text.startsWith(tempSearchString)){
 					if(lastResult == null || !lastResult.getFile().equals(file)){
 						lastResult = new FileResult(file);
 						result.getEntries().add(lastResult);
 					}
 					
-					lastResult.addPosition(node.getStartOffset()+region.getStart());
+					lastResult.addPosition(node.getStartOffset()+region.getStart()+delta);
 				}
 			}
 		}



More information about the jbosstools-commits mailing list