From: axelcl Date: Sun, 15 Jan 2006 22:12:59 +0000 (+0000) Subject: Refactoringaction: net.sourceforge.phpdt.ltk.ui.actions.RenameLocalVariable X-Git-Url: http://git.phpeclipse.com?hp=74f5d4a1bdd12f02aac9ff9fe3bd549bcfb42ceb Refactoringaction: net.sourceforge.phpdt.ltk.ui.actions.RenameLocalVariable This refactoring replaces any $-variable inside a function or method declaration The action can detect the scope of a PHP function or class method. NEW: this refactoring now replaces variables inside double quoted strings. This refactoring doesn't look for global variables inside the function or method. This refactoring doesn't look correctly for "self::" and "$this" tokens inside the function or method. This refactoring doesn't look for a preceding PHPDoc comment and therefore cannot replace any local variables inside the PHPdoc comment. --- diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ltk/core/RenameLocalVariableDelegate.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ltk/core/RenameLocalVariableDelegate.java index 11f3fd5..dfa9ce1 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ltk/core/RenameLocalVariableDelegate.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ltk/core/RenameLocalVariableDelegate.java @@ -6,8 +6,6 @@ package net.sourceforge.phpdt.ltk.core; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; import net.sourceforge.phpdt.core.ISourceRange; import net.sourceforge.phpdt.core.compiler.ITerminalSymbols; @@ -17,22 +15,17 @@ import net.sourceforge.phpdt.internal.compiler.parser.SyntaxError; import net.sourceforge.phpdt.internal.core.SourceMethod; import net.sourceforge.phpeclipse.PHPeclipsePlugin; -import org.eclipse.core.resources.IContainer; 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.IStatus; import org.eclipse.core.runtime.Status; -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.IConditionChecker; import org.eclipse.ltk.core.refactoring.participants.ValidateEditChecker; -import org.eclipse.text.edits.MultiTextEdit; -import org.eclipse.text.edits.ReplaceEdit; /** *

@@ -116,16 +109,29 @@ public class RenameLocalVariableDelegate extends RenameIdentifierDelegate { Scanner scanner = new Scanner(true, false); scanner.setSource(methodString.toCharArray()); scanner.setPHPMode(true); - char[] word = info.getOldName().toCharArray(); + String wordStr = info.getOldName(); + char[] word = wordStr.toCharArray(); int fToken = ITerminalSymbols.TokenNameEOF; + String dqStr; + int dqOffset; + int index; try { fToken = scanner.getNextToken(); while (fToken != ITerminalSymbols.TokenNameEOF) { if (fToken == ITerminalSymbols.TokenNameVariable) { if (scanner.equalsCurrentTokenSource(word)) { + // the current variable token is equal to the given word matches.add(Integer.valueOf(scanner.getCurrentTokenStartPosition() + offset)); } + } else if (fToken == ITerminalSymbols.TokenNameStringDoubleQuote) { + // determine the word in double quoted strings: + dqStr = new String(scanner.getCurrentTokenSource()); + dqOffset = scanner.getCurrentTokenStartPosition(); + index = -1; + while ((index = dqStr.indexOf(wordStr, index + 1)) >= 0) { + matches.add(Integer.valueOf(offset + dqOffset + index)); + } } fToken = scanner.getNextToken(); }